Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/36004-grid-header-help-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/fields': patch
'@object-ui/i18n': patch
---

fix(fields): the line grid's column-header help no longer becomes part of every cell's announced column name

Clause-②: yes (widening)
Metadata-protocol: none

The widening is additive: the new key `fields.grid.columnHelp` in every locale pack `@object-ui/i18n` publishes through `./locales`, in all eleven locales.

The info button beside a line grid's column header used the column's help text as its accessible name. The button sits inside the header cell, so the help joined the column header's name, and a screen reader that announces a cell's column read the whole help sentence with every cell of that column. The button is now named by a short "Help" word in the reader's language (`fields.grid.columnHelp`), and the help is its description (`aria-describedby`), read when the button is reached. The column header is named by the field label and that one word. The tooltip on hover and keyboard focus is unchanged, on the editable grid and on the read-only table.

No metadata key is added or changed.
62 changes: 58 additions & 4 deletions ui/packages/fields/src/widgets/GridField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import React from 'react';
import { UploadProvider } from './UploadProvider';
import { Dialog, DialogContent, DialogTitle } from '@object-ui/components';
import { formatDate, formatDateTime } from '@object-ui/core';
import { I18nProvider } from '@object-ui/i18n';
import { en, zh } from '@object-ui/i18n/locales';
import { GridFieldWidget as GridField } from './grid-field/GridFieldWidget';
import { GridField as GridFieldFace, LineItemsField, sumColumn, lookupAutofillPatch, UNTOUCHED_NEW_ROW, isUntouchedNewRow, columnHelpByField } from './GridField';

Expand Down Expand Up @@ -964,21 +966,21 @@ describe('no trailing entry row beside Add (objectstack#35507)', () => {
describe('column header help (objectstack#35804)', () => {
const help = { amount: 'Enter the tax-inclusive amount.' };

it('a column with help draws an info button whose accessible name is the help', () => {
it('a column with help draws an info button named Help and described by the help', () => {
render(<GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />);
const button = screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' });
const button = screen.getByRole('button', { name: 'Help', description: 'Enter the tax-inclusive amount.' });
expect(button.closest('th')!.textContent).toContain('Amount');
});

it('focusing the info button shows the help', async () => {
render(<GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />);
fireEvent.focus(screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' }));
fireEvent.focus(screen.getByRole('button', { name: 'Help' }));
expect((await screen.findByRole('tooltip')).textContent).toBe('Enter the tax-inclusive amount.');
});

it('the read-only table draws the same help', () => {
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={field} readonly columnHelp={help} />);
expect(screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' })).toBeTruthy();
expect(screen.getByRole('button', { name: 'Help', description: 'Enter the tax-inclusive amount.' })).toBeTruthy();
});

it('CONTROL: a column without help draws no info button', () => {
Expand All @@ -1000,6 +1002,58 @@ describe('column header help (objectstack#35804)', () => {
});
});

/**
* objectstack#36004 — a cell's column is announced by its header's accessible
* name, so the help must not join it. The header is named by the field label
* and the info button's short Help word; the help itself is the button's
* description, which a screen reader reads on reaching the button. Computed
* through jest-dom's accname matchers (dom-accessibility-api), on the editable
* grid and on the read-only table alike.
*
* dom-accessibility-api treats a button nested in the header as an embedded
* control and leaves its `aria-label` out of the header's name, so it reads the
* label alone whatever the button is named. A browser following accname folds
* that `aria-label` in, so the pin also holds every `aria-label` inside the
* header to the Help word: that is the text a browser adds to the column name.
*/
describe('column header help stays out of the column name (objectstack#36004)', () => {
const help = { amount: 'Enter the tax-inclusive amount.' };
const inLocale = (language: 'en' | 'zh', node: React.ReactNode) => (
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
{node}
</I18nProvider>
);

it.each([
['editable grid', false],
['read-only table', true],
])('%s: the header is named by the label and Help; the button is described by the help', (_face, readonly) => {
render(
inLocale(
'en',
<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={field} readonly={readonly} columnHelp={help} />,
),
);
const button = screen.getByTestId('line-items-column-help');
const header = button.closest('th')!;
expect(header).toHaveAccessibleName('Amount');
expect(Array.from(header.querySelectorAll('[aria-label]'), (el) => el.getAttribute('aria-label'))).toEqual([
en.fields.grid.columnHelp,
]);
expect(button).toHaveAccessibleName(en.fields.grid.columnHelp);
expect(button).toHaveAccessibleDescription('Enter the tax-inclusive amount.');
});

it('the Help word is read from the pack in the reader\'s language', () => {
expect(zh.fields.grid.columnHelp).not.toBe(en.fields.grid.columnHelp);
render(inLocale('zh', <GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />));
const button = screen.getByTestId('line-items-column-help');
expect(button).toHaveAccessibleName(zh.fields.grid.columnHelp);
expect(button).toHaveAccessibleDescription('Enter the tax-inclusive amount.');
expect(button.closest('th')).toHaveAccessibleName('Amount');
});
});

describe('cell faces that open under the cell (objectstack#36023)', () => {
const STATUS = [
{ label: 'To Do', value: 'todo' },
Expand Down
53 changes: 35 additions & 18 deletions ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,28 +445,45 @@ export type GridFieldWidgetProps = FieldWidgetComponentProps<Row[]> & {

/**
* The info button beside a column's header label (objectstack#35804): the
* column's help on hover and on keyboard focus, and the button's accessible
* name is the help itself, so a screen reader hears it on reaching the button.
* Its own provider, so the grid draws it under any host.
* column's help on hover and on keyboard focus.
*
* The button sits inside the `<th>`, so its accessible name joins the column
* header's, which a screen reader announces with every cell of the column
* (objectstack#36004). The help is therefore NOT the button's name: the button
* is named by a short Help word from the pack (`fields.grid.columnHelp`), and
* the help is its DESCRIPTION, through `aria-describedby` on a `hidden` copy
* beside it. A hidden node takes no part in the header's name from content,
* and a description reads a node it references even when it is hidden, so a
* screen reader hears "Help" and then the help on reaching the button, while
* the column stays named by its label. The text is the host's, already in the
* reader's language. Its own provider, so the grid draws it under any host.
*/
function ColumnHeaderHelp({ help }: { help: string | undefined }) {
const { t } = useFieldTranslation();
const descriptionId = React.useId();
if (!help) return null;
return (
<TooltipProvider delayDuration={200}>
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
aria-label={help}
className="ml-1 inline-flex h-4 w-4 items-center justify-center rounded-sm align-middle text-muted-foreground/70 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
data-testid="line-items-column-help"
>
<Info className="h-3.5 w-3.5" aria-hidden="true" />
</button>
</TooltipTrigger>
<TooltipContent className="max-w-xs whitespace-normal text-xs font-normal">{help}</TooltipContent>
</Tooltip>
</TooltipProvider>
<>
<TooltipProvider delayDuration={200}>
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
aria-label={t('fields.grid.columnHelp', { defaultValue: 'Help' })}
aria-describedby={descriptionId}
className="ml-1 inline-flex h-4 w-4 items-center justify-center rounded-sm align-middle text-muted-foreground/70 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
data-testid="line-items-column-help"
>
<Info className="h-3.5 w-3.5" aria-hidden="true" />
</button>
</TooltipTrigger>
<TooltipContent className="max-w-xs whitespace-normal text-xs font-normal">{help}</TooltipContent>
</Tooltip>
</TooltipProvider>
<span id={descriptionId} hidden>
{help}
</span>
</>
);
}

Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ const ar = {
openRow: "فتح الصف",
duplicateRow: "تكرار الصف",
removeRow: "إزالة الصف",
columnHelp: "المساعدة",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ const de = {
openRow: "Zeile öffnen",
duplicateRow: "Zeile duplizieren",
removeRow: "Zeile entfernen",
columnHelp: "Hilfe",
},
},
table: {
Expand Down
5 changes: 5 additions & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ const en = {
// one key, read by both its `aria-label` and its `title`. The chooser's
// button reads `table.columns`, the footer `form.masterDetail.total` and
// the drag handle `view.dragToReorder`.
//
// objectstack#36004 — `columnHelp` names a column header's info button
// with one short word; the help itself is the button's description, so it
// stays out of the column name a screen reader reads with every cell.
grid: {
addLine: 'Add line',
noItems: 'No items',
Expand All @@ -755,6 +759,7 @@ const en = {
openRow: 'Open row',
duplicateRow: 'Duplicate row',
removeRow: 'Remove row',
columnHelp: 'Help',
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ const es = {
openRow: "Abrir fila",
duplicateRow: "Duplicar fila",
removeRow: "Quitar fila",
columnHelp: "Ayuda",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ const fr = {
openRow: "Ouvrir la ligne",
duplicateRow: "Dupliquer la ligne",
removeRow: "Supprimer la ligne",
columnHelp: "Aide",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ const ja = {
openRow: "行を開く",
duplicateRow: "行を複製",
removeRow: "行を削除",
columnHelp: "ヘルプ",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ const ko = {
openRow: "행 열기",
duplicateRow: "행 복제",
removeRow: "행 삭제",
columnHelp: "도움말",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ const pt = {
openRow: "Abrir linha",
duplicateRow: "Duplicar linha",
removeRow: "Remover linha",
columnHelp: "Ajuda",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ const ru = {
openRow: "Открыть строку",
duplicateRow: "Дублировать строку",
removeRow: "Удалить строку",
columnHelp: "Помощь",
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ const zh = {
openRow: '打开行',
duplicateRow: '复制行',
removeRow: '删除行',
columnHelp: '帮助',
},
},
table: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ const zhHant = {
openRow: '開啟行',
duplicateRow: '複製行',
removeRow: '刪除行',
columnHelp: '幫助',
},
},
table: {
Expand Down
5 changes: 3 additions & 2 deletions ui/packages/plugin-form/src/MasterDetailForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,10 @@ describe('MasterDetailForm — line column headers show the child fields\' help
],
])('%s: each header carries its field\'s help, the form\'s own read of it', async (_label, detail) => {
render(<MasterDetailForm schema={schema(detail)} dataSource={ds()} />);
const qtyHelp = await screen.findByRole('button', { name: 'Whole units only.' });
// The info button is named Help and described by the help (objectstack#36004).
const qtyHelp = await screen.findByRole('button', { name: 'Help', description: 'Whole units only.' });
expect(qtyHelp.closest('th')!.textContent).toContain('Qty');
expect(screen.getByRole('button', { name: 'Tax-inclusive.' }).closest('th')!.textContent).toContain('Price');
expect(screen.getByRole('button', { name: 'Help', description: 'Tax-inclusive.' }).closest('th')!.textContent).toContain('Price');
// CONTROL: a field with no help draws no info button on its header.
expect(screen.getByRole('columnheader', { name: 'Note' }).querySelector('button')).toBeNull();
});
Expand Down
Loading