Skip to content

Commit 43580a3

Browse files
fix(fields): the line grid's column-header help no longer joins every cell's announced column name (#36486)
Fixes #36004 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:明细行表格里,读屏用户在表格中移动时,每个单元格只播报列名(外加一个"帮助"字样),不再把整句字段说明跟着每个格子念一遍;视觉上不变。 - 为什么做:这是上一张"明细表头显示字段帮助"卡的后续无障碍修正,替读屏用户解决播报冗长的问题。 - 出错会怎样:最坏是读屏用户在按钮上听不到说明,但悬停与键盘聚焦时的提示框照常显示;改动可直接撤回。 - 要你做什么:无 ## What changes - `ColumnHeaderHelp` (the info button in a line grid's column header; now in `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx` after the lazy-body split landed on main): 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 the button. A hidden node does not enter the header's name from content; a description reads a node it references even when hidden. The tooltip on hover and focus is unchanged. - `@object-ui/i18n`: new key `fields.grid.columnHelp` in all eleven locale packs (the Clause-② widening: the packs are published through `./locales`). No existing key had the value "Help": the catalogue has `sidebar.helpTooltip` ("Help & Documentation") and the `help.*` docs namespace, neither a one-word label. - `ui/packages/plugin-form/src/MasterDetailForm.test.tsx`: its 35804 test found the button by the help as its name; it now finds it by name Help and description = the help. This change made that assertion false, so it is updated here (file outside the claim's surface, named in the report). - Changeset `.changeset/36004-grid-header-help-name.md` (`@object-ui/fields`, `@object-ui/i18n`: patch). ## Tests - New top-level describe in `GridField.test.tsx`, `column header help stays out of the column name (objectstack#36004)`: on the editable grid and the read-only table, the header's accessible name, every `aria-label` inside the header (only the Help word), the button's name (Help word) and its description (the help); plus the zh pack under zh. The existing 35804 tests now find the button by name Help and description = the help. - How the accname helper reads it: jest-dom's `toHaveAccessibleName` (dom-accessibility-api) treats a button nested in the header as an embedded control and drops its `aria-label`. So it reads the header as `Amount` on origin/main and on this branch alike, and the header-name assertion alone cannot tell them apart. The pin therefore also holds the `aria-label`s inside the header, which is the text a spec-following browser adds. - Chromium (CDP `Accessibility.getFullAXTree`, static markup of both shapes): origin/main shape, column header `Amount Enter the tax-inclusive amount.`; this branch's shape, column header `Amount Help`, button name `Help`, description `Enter the tax-inclusive amount.`. <details><summary>Ablation (head 7daa1e4): origin/main's component under this branch's tests and packs</summary> - Mutation: `git restore --source=c13af73039 -- ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx` (tree only). On disk: `fields.grid.columnHelp` count 0, `aria-label={help}` count 1. - Run: `vitest run packages/fields/src/widgets/GridField.test.tsx -t 'objectstack#36004|objectstack#35804'` gives `Tests 6 failed | 2 passed | 87 skipped`. For example, `Expected element to have accessible name: 帮助 / Received: Enter the tax-inclusive amount.` - Restore: `git checkout HEAD -- <abs path>`, hash `baa9863a23` == HEAD blob, `git diff HEAD` empty. Re-run gives `Tests 8 passed | 87 skipped`. - The subject is imported relatively from `src`, so no `dist/` leg applies. </details> <details><summary>Suites and type-check (head 7daa1e4)</summary> - `pnpm --dir ui exec vitest run packages/fields/src/widgets/GridField.test.tsx packages/plugin-form/src/MasterDetailForm.test.tsx packages/i18n/src/__tests__/all-locales-key-parity.test.ts packages/i18n/src/__tests__/en-zh-key-parity.test.ts`: `Test Files 4 passed (4) · Tests 166 passed (166)` - `pnpm --dir ui exec vitest run packages/fields/ packages/i18n/`: `Test Files 428 passed | 1 skipped (429) · Tests 6829 passed | 20 skipped (6849)` - `turbo run build --filter='@object-ui/plugin-form^...' --filter='@object-ui/i18n^...'` exit 0, then `type-check` for `@object-ui/fields`, `@object-ui/i18n` and `@object-ui/plugin-form`: exit 0 each. </details> ## Acceptance notes - The card's pin wording says "label only". The header names the label plus the one Help word, which done-when bullet 1 allows ("plus at most a short Help word"). The helper reads `Amount` and Chromium reads `Amount Help`; both are pinned as described above. - The editable header keeps its required ` *` mark in the header text, as before. ## Verification Risk-ranked first reads: 1. `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx`, `ColumnHeaderHelp`: the `aria-describedby` target is the `hidden` span, and the hooks run before the early return. 2. `ui/packages/fields/src/widgets/GridField.test.tsx`, the `objectstack#36004` describe. 3. `ui/packages/i18n/src/locales/en.ts`, `fields.grid.columnHelp`. Two-minute check: `pnpm --dir ui exec vitest run packages/fields/src/widgets/GridField.test.tsx -t 'objectstack#36004'` should show 3 passed. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f2ef7d8 commit 43580a3

15 files changed

Lines changed: 126 additions & 24 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/fields': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(fields): the line grid's column-header help no longer becomes part of every cell's announced column name
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
The widening is additive: the new key `fields.grid.columnHelp` in every locale pack `@object-ui/i18n` publishes through `./locales`, in all eleven locales.
12+
13+
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.
14+
15+
No metadata key is added or changed.

‎ui/packages/fields/src/widgets/GridField.test.tsx‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import React from 'react';
44
import { UploadProvider } from './UploadProvider';
55
import { Dialog, DialogContent, DialogTitle } from '@object-ui/components';
66
import { formatDate, formatDateTime } from '@object-ui/core';
7+
import { I18nProvider } from '@object-ui/i18n';
8+
import { en, zh } from '@object-ui/i18n/locales';
79
import { GridFieldWidget as GridField } from './grid-field/GridFieldWidget';
810
import { GridField as GridFieldFace, LineItemsField, sumColumn, lookupAutofillPatch, UNTOUCHED_NEW_ROW, isUntouchedNewRow, columnHelpByField } from './GridField';
911

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

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

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

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

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

1005+
/**
1006+
* objectstack#36004 — a cell's column is announced by its header's accessible
1007+
* name, so the help must not join it. The header is named by the field label
1008+
* and the info button's short Help word; the help itself is the button's
1009+
* description, which a screen reader reads on reaching the button. Computed
1010+
* through jest-dom's accname matchers (dom-accessibility-api), on the editable
1011+
* grid and on the read-only table alike.
1012+
*
1013+
* dom-accessibility-api treats a button nested in the header as an embedded
1014+
* control and leaves its `aria-label` out of the header's name, so it reads the
1015+
* label alone whatever the button is named. A browser following accname folds
1016+
* that `aria-label` in, so the pin also holds every `aria-label` inside the
1017+
* header to the Help word: that is the text a browser adds to the column name.
1018+
*/
1019+
describe('column header help stays out of the column name (objectstack#36004)', () => {
1020+
const help = { amount: 'Enter the tax-inclusive amount.' };
1021+
const inLocale = (language: 'en' | 'zh', node: React.ReactNode) => (
1022+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
1023+
{node}
1024+
</I18nProvider>
1025+
);
1026+
1027+
it.each([
1028+
['editable grid', false],
1029+
['read-only table', true],
1030+
])('%s: the header is named by the label and Help; the button is described by the help', (_face, readonly) => {
1031+
render(
1032+
inLocale(
1033+
'en',
1034+
<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={field} readonly={readonly} columnHelp={help} />,
1035+
),
1036+
);
1037+
const button = screen.getByTestId('line-items-column-help');
1038+
const header = button.closest('th')!;
1039+
expect(header).toHaveAccessibleName('Amount');
1040+
expect(Array.from(header.querySelectorAll('[aria-label]'), (el) => el.getAttribute('aria-label'))).toEqual([
1041+
en.fields.grid.columnHelp,
1042+
]);
1043+
expect(button).toHaveAccessibleName(en.fields.grid.columnHelp);
1044+
expect(button).toHaveAccessibleDescription('Enter the tax-inclusive amount.');
1045+
});
1046+
1047+
it('the Help word is read from the pack in the reader\'s language', () => {
1048+
expect(zh.fields.grid.columnHelp).not.toBe(en.fields.grid.columnHelp);
1049+
render(inLocale('zh', <GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />));
1050+
const button = screen.getByTestId('line-items-column-help');
1051+
expect(button).toHaveAccessibleName(zh.fields.grid.columnHelp);
1052+
expect(button).toHaveAccessibleDescription('Enter the tax-inclusive amount.');
1053+
expect(button.closest('th')).toHaveAccessibleName('Amount');
1054+
});
1055+
});
1056+
10031057
describe('cell faces that open under the cell (objectstack#36023)', () => {
10041058
const STATUS = [
10051059
{ label: 'To Do', value: 'todo' },

‎ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,28 +445,45 @@ export type GridFieldWidgetProps = FieldWidgetComponentProps<Row[]> & {
445445

446446
/**
447447
* The info button beside a column's header label (objectstack#35804): the
448-
* column's help on hover and on keyboard focus, and the button's accessible
449-
* name is the help itself, so a screen reader hears it on reaching the button.
450-
* Its own provider, so the grid draws it under any host.
448+
* column's help on hover and on keyboard focus.
449+
*
450+
* The button sits inside the `<th>`, so its accessible name joins the column
451+
* header's, which a screen reader announces with every cell of the column
452+
* (objectstack#36004). The help is therefore NOT the button's name: the button
453+
* is named by a short Help word from the pack (`fields.grid.columnHelp`), and
454+
* the help is its DESCRIPTION, through `aria-describedby` on a `hidden` copy
455+
* beside it. A hidden node takes no part in the header's name from content,
456+
* and a description reads a node it references even when it is hidden, so a
457+
* screen reader hears "Help" and then the help on reaching the button, while
458+
* the column stays named by its label. The text is the host's, already in the
459+
* reader's language. Its own provider, so the grid draws it under any host.
451460
*/
452461
function ColumnHeaderHelp({ help }: { help: string | undefined }) {
462+
const { t } = useFieldTranslation();
463+
const descriptionId = React.useId();
453464
if (!help) return null;
454465
return (
455-
<TooltipProvider delayDuration={200}>
456-
<Tooltip>
457-
<TooltipTrigger asChild>
458-
<button
459-
type="button"
460-
aria-label={help}
461-
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"
462-
data-testid="line-items-column-help"
463-
>
464-
<Info className="h-3.5 w-3.5" aria-hidden="true" />
465-
</button>
466-
</TooltipTrigger>
467-
<TooltipContent className="max-w-xs whitespace-normal text-xs font-normal">{help}</TooltipContent>
468-
</Tooltip>
469-
</TooltipProvider>
466+
<>
467+
<TooltipProvider delayDuration={200}>
468+
<Tooltip>
469+
<TooltipTrigger asChild>
470+
<button
471+
type="button"
472+
aria-label={t('fields.grid.columnHelp', { defaultValue: 'Help' })}
473+
aria-describedby={descriptionId}
474+
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"
475+
data-testid="line-items-column-help"
476+
>
477+
<Info className="h-3.5 w-3.5" aria-hidden="true" />
478+
</button>
479+
</TooltipTrigger>
480+
<TooltipContent className="max-w-xs whitespace-normal text-xs font-normal">{help}</TooltipContent>
481+
</Tooltip>
482+
</TooltipProvider>
483+
<span id={descriptionId} hidden>
484+
{help}
485+
</span>
486+
</>
470487
);
471488
}
472489

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ const ar = {
509509
openRow: "فتح الصف",
510510
duplicateRow: "تكرار الصف",
511511
removeRow: "إزالة الصف",
512+
columnHelp: "المساعدة",
512513
},
513514
},
514515
table: {

‎ui/packages/i18n/src/locales/de.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ const de = {
487487
openRow: "Zeile öffnen",
488488
duplicateRow: "Zeile duplizieren",
489489
removeRow: "Zeile entfernen",
490+
columnHelp: "Hilfe",
490491
},
491492
},
492493
table: {

‎ui/packages/i18n/src/locales/en.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ const en = {
746746
// one key, read by both its `aria-label` and its `title`. The chooser's
747747
// button reads `table.columns`, the footer `form.masterDetail.total` and
748748
// the drag handle `view.dragToReorder`.
749+
//
750+
// objectstack#36004 — `columnHelp` names a column header's info button
751+
// with one short word; the help itself is the button's description, so it
752+
// stays out of the column name a screen reader reads with every cell.
749753
grid: {
750754
addLine: 'Add line',
751755
noItems: 'No items',
@@ -755,6 +759,7 @@ const en = {
755759
openRow: 'Open row',
756760
duplicateRow: 'Duplicate row',
757761
removeRow: 'Remove row',
762+
columnHelp: 'Help',
758763
},
759764
},
760765
table: {

‎ui/packages/i18n/src/locales/es.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ const es = {
496496
openRow: "Abrir fila",
497497
duplicateRow: "Duplicar fila",
498498
removeRow: "Quitar fila",
499+
columnHelp: "Ayuda",
499500
},
500501
},
501502
table: {

‎ui/packages/i18n/src/locales/fr.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ const fr = {
491491
openRow: "Ouvrir la ligne",
492492
duplicateRow: "Dupliquer la ligne",
493493
removeRow: "Supprimer la ligne",
494+
columnHelp: "Aide",
494495
},
495496
},
496497
table: {

‎ui/packages/i18n/src/locales/ja.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ const ja = {
487487
openRow: "行を開く",
488488
duplicateRow: "行を複製",
489489
removeRow: "行を削除",
490+
columnHelp: "ヘルプ",
490491
},
491492
},
492493
table: {

‎ui/packages/i18n/src/locales/ko.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ const ko = {
487487
openRow: "행 열기",
488488
duplicateRow: "행 복제",
489489
removeRow: "행 삭제",
490+
columnHelp: "도움말",
490491
},
491492
},
492493
table: {

0 commit comments

Comments
 (0)