diff --git a/.changeset/36004-grid-header-help-name.md b/.changeset/36004-grid-header-help-name.md new file mode 100644 index 00000000000..823f572db73 --- /dev/null +++ b/.changeset/36004-grid-header-help-name.md @@ -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. diff --git a/ui/packages/fields/src/widgets/GridField.test.tsx b/ui/packages/fields/src/widgets/GridField.test.tsx index f1bfbfc24d1..219ea575c92 100644 --- a/ui/packages/fields/src/widgets/GridField.test.tsx +++ b/ui/packages/fields/src/widgets/GridField.test.tsx @@ -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'; @@ -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( {}} 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( {}} 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( {}} 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', () => { @@ -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) => ( + + {node} + + ); + + 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', + {}} 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', {}} 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' }, diff --git a/ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx b/ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx index e23f10e5198..baa9863a23c 100644 --- a/ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx +++ b/ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx @@ -445,28 +445,45 @@ export type GridFieldWidgetProps = FieldWidgetComponentProps & { /** * 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 ``, 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 ( - - - - - - {help} - - + <> + + + + + + {help} + + + + ); } diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index c3010486d99..1fb9545934b 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -509,6 +509,7 @@ const ar = { openRow: "فتح الصف", duplicateRow: "تكرار الصف", removeRow: "إزالة الصف", + columnHelp: "المساعدة", }, }, table: { diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index ffedd874ffd..fc4803746a2 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -487,6 +487,7 @@ const de = { openRow: "Zeile öffnen", duplicateRow: "Zeile duplizieren", removeRow: "Zeile entfernen", + columnHelp: "Hilfe", }, }, table: { diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index bc51e535396..f4905cb6462 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -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', @@ -755,6 +759,7 @@ const en = { openRow: 'Open row', duplicateRow: 'Duplicate row', removeRow: 'Remove row', + columnHelp: 'Help', }, }, table: { diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 4eb1416c2e9..e47db76646d 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -496,6 +496,7 @@ const es = { openRow: "Abrir fila", duplicateRow: "Duplicar fila", removeRow: "Quitar fila", + columnHelp: "Ayuda", }, }, table: { diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 2897ba30a6d..c26fced4ac8 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -491,6 +491,7 @@ const fr = { openRow: "Ouvrir la ligne", duplicateRow: "Dupliquer la ligne", removeRow: "Supprimer la ligne", + columnHelp: "Aide", }, }, table: { diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 8e905217048..95fc5c83689 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -487,6 +487,7 @@ const ja = { openRow: "行を開く", duplicateRow: "行を複製", removeRow: "行を削除", + columnHelp: "ヘルプ", }, }, table: { diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 0b863615fd9..9a3f70ca656 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -487,6 +487,7 @@ const ko = { openRow: "행 열기", duplicateRow: "행 복제", removeRow: "행 삭제", + columnHelp: "도움말", }, }, table: { diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index fa337da7bd4..7870bac9231 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -491,6 +491,7 @@ const pt = { openRow: "Abrir linha", duplicateRow: "Duplicar linha", removeRow: "Remover linha", + columnHelp: "Ajuda", }, }, table: { diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 22a331c1f3b..c82a2b37129 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -498,6 +498,7 @@ const ru = { openRow: "Открыть строку", duplicateRow: "Дублировать строку", removeRow: "Удалить строку", + columnHelp: "Помощь", }, }, table: { diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 3937118eb1a..03b3d3dff7b 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -500,6 +500,7 @@ const zh = { openRow: '打开行', duplicateRow: '复制行', removeRow: '删除行', + columnHelp: '帮助', }, }, table: { diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index e27f1bad492..f157161f348 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -500,6 +500,7 @@ const zhHant = { openRow: '開啟行', duplicateRow: '複製行', removeRow: '刪除行', + columnHelp: '幫助', }, }, table: { diff --git a/ui/packages/plugin-form/src/MasterDetailForm.test.tsx b/ui/packages/plugin-form/src/MasterDetailForm.test.tsx index 473e762e828..2c146ed35a5 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.test.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.test.tsx @@ -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(); - 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(); });