Skip to content

Commit ec24363

Browse files
fix(fields): the line grid draws no blank entry row beside Add, and its column headers show each field's help (#35998)
Fixes #35507 Fixes #35804 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在主从表单的明细行表格里,业务用户编辑报价、订单时:以前已有行下面总多一条删不掉的空白行,现在只显示真实的行;每列表头旁多了一个小图标,鼠标悬停或用键盘移上去就显示该字段的填写说明。 - 属于体验改进,替通过明细表格录入的业务用户解决"空白行像坏行"和"填写规则在表格里看不到"这两个问题。 - 出错时最坏是表格里少了空白录入行或说明图标不显示,保存发送的内容不变,可以直接撤回本次改动。 - 无。 ## What changes **#35507: no blank entry row beside "Add line".** `GridField` used to append an always-present empty "ghost" line under the lines (`hasGhost` / `displayRows`), directly above the Add button. It had no copy or remove action and produced no write. The grid no longer draws it. - Premise as measured on `origin/main` (`9a8bb83d`): the ghost row and the Add button were both gated on `allowAdd`, so the ghost was **only ever drawn where Add was drawn**. Dropping it leaves no grid without a way to add a line. The "Add not drawn" branch of the order has nothing to restyle: with `allowAdd: false` there was never a ghost row, and that stays true (CONTROL pin). - An empty editable grid now shows the existing `fields.grid.noItemsAddHint` ("No items yet — click "Add line" to begin.") with the Add button's real label. No new i18n key. - Keyboard path kept. On main a keyboard user could Tab or Enter into the ghost line and type. Now: **Add moves focus into the line it appends** (Tab reaches Add after the last line), and **Enter in the last line appends a line and moves to the same column in it** (only when adding is allowed). - One narrow state still draws the entry line: a **required grid the form refused while empty** (`hostFailedEmpty`, objectui#3318). There the line carries the field's failure to assistive tech on the cells a user types into. The Add button is an action, not the invalid control. `widget-aria-invalid-registry-e2e` stays green because this line still exists. - Saving is unchanged. An edit emits exactly the lines (CONTROL pin), and a line added through Add then typed sends the same create the ghost line did. 23 plugin-form test files read the ghost line as the entry path. Each one now presses Add first, with the expected lengths and the batch payloads unchanged. **#35804: column headers show each field's help.** Each grid column header now draws an info icon beside its label when the field has help. The help shows on hover and on keyboard focus (Radix tooltip), and the icon button's accessible name is the help text. The editable grid and the read-only table both draw it. - Help source: a grid column (`InlineGridColumn`) is a strict spec shape with no help key. No spec key is added. Following the `lookupAutofill` / `columnCurrencies` pattern, the host that holds the child object's definition passes the help through a new `GridField` prop, `columnHelp`. New helper: `columnHelpByField(fields)`. It reads each field through `fieldHelpText`, the same function the record form's help line uses (`inlineHelpText`, else `description`), so the header and the form show the same text. - The child definition is the one `dataSource.getObjectSchema(child)` serves, which the record form also reads. The server applies `objectExtensions.fieldPatches` before serving it and translates the help into the reader's locale (`packages/rest/src/meta-object-field-patch-i18n.test.ts` pins both on the served object). The grid does not re-resolve anything. - Wired in the three line-grid hosts: `MasterDetailForm`, `LineItemsPanel` and `RecordBodyTableEditor`. ## Tests All runs are at head `d4100395`, through `scripts/pm/os-verify-lock.sh`. - New pins in `GridField.test.tsx` (two top-level describes) and `MasterDetailForm.test.tsx` (one describe). - On the base, the 9 non-control pins were red: `9 failed | 59 passed`. The four CONTROL pins (Add off, edit emit, Enter with Add off, no-help header) were green on both trees. - `cd ui && pnpm exec vitest run packages/fields/ packages/plugin-form/`: **Test Files 549 passed | 1 skipped (550), Tests 7402 passed | 8 skipped (7410)**, VERDICT command-exit 0. - `pnpm --filter @object-ui/fields run type-check` and `pnpm --filter @object-ui/plugin-form run type-check` both passed after building their `@object-ui` dependency closure. VERDICT command-exit 0. <details><summary>Ablations (one per fix, through scripts/ablation-replace.mjs, restored to the HEAD blob)</summary> - Ghost row back (`hasGhost` without `hostFailedEmpty`): 4 pins red (lines-only, empty state, Add focus, Enter append) and 3 controls green. Restore: blob `1a5224d841fb` == HEAD, `git diff HEAD` empty. - Header help off (`ColumnHeaderHelp` returns null): 5 pins red (accessible name, focus tooltip, read-only table, and both MasterDetailForm host cases). Restore: blob == HEAD, `git diff HEAD` empty. </details> ## Browser reading (A4) This run used the showcase on its own `--fresh` backend (:4371) and the Console dev server (:5371) built from this branch, in headless Chromium at 1280×900 with deviceScaleFactor 2. The invoice INV-1010 edit form has one stored line. For the reading only, two fixtures were added and then reverted (neither is in this PR): a declared `inlineHelpText` on `showcase_invoice_line.quantity`, and an object extension whose `fieldPatches` set `unit_price.inlineHelpText` to 「内销填含税价,出口填不含税的 FOB 美元价」. - tbody rows: 1, the stored line only. The row above Add line is "1 · Widget B · … · $230.00", with no blank trailing row. - Help icons: `Qty *` is named "Whole units; bill partial hours as decimals." (declared), and `Unit Price` is named 「内销填含税价,出口填不含税的 FOB 美元价」 (fieldPatches). Other headers have no icon. - Hovering the Unit Price icon shows a tooltip with the patched text. Keyboard focus on the Qty icon shows a tooltip with the declared text, and `activeElement`'s accessible name is that help. - Clicking Add line leaves the focus on `data-cell="1-1"` (Description) of the new line. The first column is a lookup with no text cell. - Screenshots (seat share): `a4-35507/1-edit-form-no-trailing-row.png`, `2-grid-no-trailing-row.png`, `3-hover-help-fieldPatches-unit-price.png`, `4-focus-help-declared-qty.png`, `5-after-add-focus-in-new-line.png`. ## Acceptance notes - File surface: the claim names `GridField.tsx`, its tests, i18n keys and a changeset. This PR also touches `ui/packages/fields/src/index.tsx` (one export line), the three host files (`MasterDetailForm.tsx`, `LineItemsPanel.tsx`, `RecordBodyTableEditor.tsx`, which pass `columnHelp`), and 23 plugin-form test files that typed into the removed ghost line. These include `discardGuard.test.tsx` and `__tests__/modalMaximize-34604.test.tsx`, which exercise ModalForm; `ModalForm.tsx` itself is untouched. The order's direction for #35804 (find the resolved source the form uses) cannot be met from `GridField.tsx` alone, because the grid holds no field definition. - Reach of the help: a master-detail entry whose `relationshipField` and every column `type` are authored loads no child schema (an existing short-circuit in `MasterDetailForm`), so its headers show no help, just as it gets no `lookupAutofill`. The console's own path (`inlineColumns` names, hydrated from the child schema) loads it, and the showcase reading above went through that path. ## Verification Read first, by risk: 1. `ui/packages/fields/src/widgets/GridField.tsx`: the `hasGhost` / `hostFailedEmpty` hunk and `pendingFocus` / `addRow` / `onCellKeyDown`. 2. `ui/packages/plugin-form/src/MasterDetailForm.tsx`: `columnHelp` at both resolve sites and on the grid. 3. `ui/packages/fields/src/widgets/GridField.test.tsx`: the two new top-level describes. Two-minute check: `cd ui && pnpm exec vitest run packages/fields/src/widgets/GridField.test.tsx -t "objectstack#35(507|804)"` should print 12 passed (the new pins). <details><summary>Local gates (derived by dispatch-gates --commands, 40 commands, all EXIT=0 at d410039)</summary> check-adr-0087-registration (+self-test), check-changeset-no-major, check-closing-keyword-parity (+self-test), check-comment-mask-corpus, check-empty-changeset (+self-test), check-sdui-manifest (+self-test), snapshot-next self-test, check-governed-queue-guard self-test, release-rehearsal-clone self-test, release-pending-publish self-test, `pnpm --dir ui exec vitest run scripts/`, spec check:duration-unit-keys, spec check:error-code-provenance, check:adr-anchors, check:changeset-gate-self-tests, check:closed-ceremony-text, check:cross-package-test-inputs, check:dispatcher-error-vocabulary, check:driver-memory-census, check:engine-double-contract, check:error-status-conformance, check:gitlink-declared, check:nul-bytes, check:published-files, check:query-options-erasure, check:refd-timer-probe, check:registry-log-declared, check:rest-log-spy-declared, check:skill-identifier-liveness, check:test-source-alias, check:tier-file-adoption, check:type-check-coverage, check:type-check-debt, check:undeclared-dep-imports, check:watch-hint-literal, check:where-matcher. Lint and the whole-workspace type-check lanes are left to CI. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CZrgaiMgTJCnswR6jQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a6607c7 commit ec24363

32 files changed

Lines changed: 542 additions & 121 deletions
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/plugin-form': patch
4+
---
5+
6+
fix(fields): the inline line grid draws no blank entry row beside "Add line", and each column header shows its field's help
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The inline line grid of a master-detail form always drew an empty line under the lines, directly above the "Add line" button. It had no copy or remove action and was never saved, so users read it as a broken line they could not delete. The grid no longer draws it: a grid with lines shows exactly its lines, and an empty grid says "No items yet — click "Add line" to begin." The keyboard path that line carried stays: "Add line" moves focus into the line it adds, and Enter in the last line adds a line and moves to the same column in it. An empty required grid that the form refused still draws one entry line, so the field's failure stays on the cells a user types into.
12+
13+
Each column header now shows its field's help as an info icon beside the label. The help appears on hover and on keyboard focus, and it is the icon's accessible name. The text is what the record form shows under the same field: `inlineHelpText`, else `description`, from the child object's definition as the server serves it, so help written by another package's `objectExtensions.fieldPatches` and the reader's language both apply. `GridField` takes the texts as a new `columnHelp` prop, and `columnHelpByField` builds them from a child object's fields. The master-detail form, the line-items panel and the record-body table editor pass them.
14+
15+
What does not change: what a save sends, the `allowAdd` / `allowDelete` / `maxRows` behaviour, and every metadata key, value and default. A master-detail entry whose relationship and every column type are authored loads no child schema, so its headers show no help, as it has no lookup autofill.

‎ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,8 @@ describe('RecordDetailView.recordEditState-35599', () => {
30363036
const lines = editor(container, 'showcase_line.quote')!;
30373037
fireEvent.change(cells(lines, 'Quantity')[0], { target: { value: '5' } });
30383038
fireEvent.click(lines.querySelectorAll('button[aria-label="Remove row"]')[1] as HTMLElement);
3039+
// The new line comes from Add: the grid draws no blank entry line beside it (objectstack#35507).
3040+
fireEvent.click(lines.querySelector('[data-testid="line-items-add"]') as HTMLElement);
30393041
const products = cells(lines, 'Product');
30403042
fireEvent.change(products[products.length - 1], { target: { value: 'Crate' } });
30413043
const tasks = editor(container, 'showcase_task.quote')!;

‎ui/packages/fields/src/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5417,8 +5417,8 @@ export * from './widgets/AutoNumberField.js';
54175417
export * from './widgets/UserField.js';
54185418
export * from './widgets/ObjectField.js';
54195419
export * from './widgets/VectorField.js';
5420-
export { evalArith, lookupAutofillPatch, computeRow, GridField, LineItemsField, UNTOUCHED_NEW_ROW, isUntouchedNewRow } from './widgets/GridField.js';
5421-
export type { ColumnCurrencies } from './widgets/GridField.js';
5420+
export { evalArith, lookupAutofillPatch, computeRow, GridField, LineItemsField, UNTOUCHED_NEW_ROW, isUntouchedNewRow, columnHelpByField } from './widgets/GridField.js';
5421+
export type { ColumnCurrencies, ColumnHelp } from './widgets/GridField.js';
54225422
export type { GridColumn } from './widgets/GridField.js';
54235423
export * from './widgets/lookupAutofill.js';
54245424
// objectstack#32770 (ADR-0150 D8 R1) — the grant's set-name column and the

‎ui/packages/fields/src/widgets/GridField.sortFieldCellEdit-12286.test.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ describe('GridField: a cell edit renumbers no row (objectui#12286)', () => {
5757
expect(next).toEqual([rows[0], { ...rows[1], description: 'B2' }]);
5858
});
5959

60-
it('CONTROL: typing into the trailing entry row ADDS a line, and an add renumbers every row', () => {
61-
const next = typeInto([{ description: 'A', position: 0 }, { description: 'B', position: 0 }], 2, 'C');
60+
it('CONTROL: Add appends a line, and an add renumbers every row', () => {
61+
// The trailing entry line this used to type into is gone (objectstack#35507);
62+
// Add is the add, and it renumbers as the entry line did.
63+
const onChange = vi.fn();
64+
render(<GridField value={[{ description: 'A', position: 0 }, { description: 'B', position: 0 }]} onChange={onChange} field={field} />);
65+
fireEvent.click(screen.getByTestId('line-items-add'));
66+
const next: Row[] = onChange.mock.calls[0][0];
6267
expect(next.map((r) => [r.description, r.position])).toEqual([
6368
['A', 0],
6469
['B', 1],
65-
['C', 2],
70+
[null, 2],
6671
]);
6772
});
6873
});

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

Lines changed: 136 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
33
import React from 'react';
44
import { UploadProvider } from './UploadProvider';
55
import { formatDate, formatDateTime } from '@object-ui/core';
6-
import { GridField, LineItemsField, sumColumn, lookupAutofillPatch, UNTOUCHED_NEW_ROW, isUntouchedNewRow } from './GridField';
6+
import { GridField, LineItemsField, sumColumn, lookupAutofillPatch, UNTOUCHED_NEW_ROW, isUntouchedNewRow, columnHelpByField } from './GridField';
77

88
const columns = [
99
{ name: 'description', label: 'Description', type: 'text' as const },
@@ -102,7 +102,7 @@ describe('GridField / LineItemsField — editable line items', () => {
102102
it('editing a text cell emits the raw string', () => {
103103
const onChange = vi.fn();
104104
render(<GridField value={[{ description: '', amount: null }]} onChange={onChange} field={field} />);
105-
// [0] = the data row ([1] would be the always-present trailing ghost row).
105+
// [0] = the data row.
106106
fireEvent.change(screen.getAllByLabelText('Description')[0], { target: { value: 'Taxi' } });
107107
expect(onChange).toHaveBeenCalledWith([{ description: 'Taxi', amount: null }]);
108108
});
@@ -369,24 +369,23 @@ describe('GridField / LineItemsField — editable line items', () => {
369369
});
370370
});
371371

372-
describe('trailing ghost row (start-with-one + auto-append)', () => {
373-
it('renders a trailing empty row so an empty grid still has one input line', () => {
374-
render(<GridField value={[]} onChange={() => {}} field={field} />);
375-
// No "No items" empty-state in grid mode — the ghost row IS the first line.
376-
expect(screen.getByText('Description')).toBeTruthy();
377-
expect(screen.getAllByLabelText('Description')).toHaveLength(1); // just the ghost
372+
// objectstack#35507 — the always-present trailing entry line is gone (see
373+
// the top-level `no trailing entry row beside Add` pins). It is drawn only
374+
// for an empty grid the form refused (objectui#3318), and there typing
375+
// into it still materialises the line.
376+
describe('the entry line of an empty grid the form refused', () => {
377+
it('is drawn only once the form reports the failure', () => {
378+
const { rerender } = render(<GridField value={[]} onChange={() => {}} field={field} />);
379+
expect(screen.queryAllByLabelText('Description')).toHaveLength(0);
380+
rerender(<GridField value={[]} onChange={() => {}} field={field} error="Lines is required" />);
381+
expect(screen.getAllByLabelText('Description')).toHaveLength(1);
378382
});
379383

380-
it('typing in the ghost row materialises a new row (no Add click needed)', () => {
384+
it('typing into it materialises a new line', () => {
381385
const onChange = vi.fn();
382-
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={onChange} field={field} />);
383-
const inputs = screen.getAllByLabelText('Description');
384-
expect(inputs).toHaveLength(2); // data row + ghost
385-
fireEvent.change(inputs[1], { target: { value: 'B' } }); // type in the ghost
386-
expect(onChange).toHaveBeenCalledWith([
387-
{ description: 'A', amount: 1 },
388-
{ description: 'B', amount: null },
389-
]);
386+
render(<GridField value={[]} onChange={onChange} field={field} error="Lines is required" />);
387+
fireEvent.change(screen.getByLabelText('Description'), { target: { value: 'B' } });
388+
expect(onChange).toHaveBeenCalledWith([{ description: 'B', amount: null }]);
390389
});
391390
});
392391

@@ -508,12 +507,12 @@ describe('GridField / LineItemsField — editable line items', () => {
508507
]);
509508
});
510509

511-
it('flags a required, empty cell on a real row (not the ghost row)', () => {
510+
it('flags a required, empty cell on a real row', () => {
512511
const reqField = { columns: [{ name: 'description', label: 'Description', type: 'text' as const, required: true }] } as any;
513512
render(<GridField value={[{ description: '' }]} onChange={() => {}} field={reqField} />);
514513
// The data row's required-empty cell is flagged...
515514
expect(screen.getByTestId('line-items-invalid-0-description')).toBeTruthy();
516-
// ...but the trailing ghost row (index 1) is not.
515+
// ...and no line below it is drawn to flag (objectstack#35507).
517516
expect(screen.queryByTestId('line-items-invalid-1-description')).toBeNull();
518517
});
519518
});
@@ -528,7 +527,7 @@ describe('GridField / LineItemsField — editable line items', () => {
528527

529528
it('renders a real upload control in the cell, not a text input', () => {
530529
render(<GridField value={[{ description: 'Taxi', receipt: null }]} onChange={() => {}} field={fileField} />);
531-
// One upload button per row (data row + ghost), backed by a native file input.
530+
// One upload button per row, backed by a native file input.
532531
expect(screen.getAllByRole('button', { name: 'Receipt' }).length).toBeGreaterThan(0);
533532
expect(document.querySelector('input[type="file"]')).toBeTruthy();
534533
expect(screen.queryByRole('textbox', { name: 'Receipt' })).toBeNull();
@@ -591,14 +590,14 @@ describe('GridField / LineItemsField — editable line items', () => {
591590
expect(cell.getAttribute('aria-invalid')).toBeNull();
592591
});
593592

594-
it('does not announce invalid on an optional empty file cell or on the ghost row', () => {
593+
it('does not announce invalid on an optional empty file cell', () => {
595594
const optFileField = {
596595
columns: [{ name: 'receipt', label: 'Receipt', type: 'file' as const }],
597596
} as any;
598597
const { container } = render(
599598
<GridField value={[{ receipt: null }]} onChange={() => {}} field={optFileField} />,
600599
);
601-
// Data row and ghost row each render a picker; none may announce invalid.
600+
// The data row renders a picker; it may not announce invalid.
602601
expect(container.querySelector('[aria-invalid="true"]')).toBeNull();
603602
});
604603

@@ -621,7 +620,7 @@ describe('GridField / LineItemsField — editable line items', () => {
621620
const withAccept = {
622621
columns: [{ name: 'receipt', label: 'Receipt', type: 'file' as const, accept: ['image/*', '.pdf'] }],
623622
} as any;
624-
render(<GridField value={[]} onChange={() => {}} field={withAccept} />);
623+
render(<GridField value={[{ receipt: null }]} onChange={() => {}} field={withAccept} />);
625624
const input = document.querySelector('input[type="file"]') as HTMLInputElement;
626625
expect(input.getAttribute('accept')).toBe('image/*,.pdf');
627626
});
@@ -791,8 +790,10 @@ describe('GridField — a new line starts on its defaults and waits to read red
791790

792791
it('Add and the entry line both start a line on the host\'s values', () => {
793792
const onChange = vi.fn();
793+
// The entry line is drawn for an empty grid the form refused
794+
// (objectstack#35507), so the failure is handed in.
794795
const { container } = render(
795-
<GridField value={[]} onChange={onChange} field={taskColumns} newRowValues={{ status: 'pending' }} />,
796+
<GridField value={[]} onChange={onChange} field={taskColumns} newRowValues={{ status: 'pending' }} error="Tasks is required" />,
796797
);
797798
fireEvent.click(screen.getByRole('button', { name: /Add line/i }));
798799
expect(onChange).toHaveBeenLastCalledWith([{ name: null, status: 'pending', [UNTOUCHED_NEW_ROW]: true }]);
@@ -845,3 +846,114 @@ describe('GridField — a new line starts on its defaults and waits to read red
845846
expect(screen.getByTestId('line-items-invalid-0-name')).toBeTruthy();
846847
});
847848
});
849+
850+
/**
851+
* objectstack#35507 — no blank entry row beside "Add line". The grid used to
852+
* append an always-present empty "ghost" line under the data rows; it carried
853+
* no actions, produced no write, and sat directly above the Add button that
854+
* does the same job, so users read it as a broken line they could not delete.
855+
* It was drawn only when Add was drawn (both follow `allowAdd`), so dropping it
856+
* leaves no grid without a way to add a line. The keyboard path it carried
857+
* (Tab or Enter into an empty line and type) is kept by Add moving focus into
858+
* the new line and by Enter on the last line appending one.
859+
*/
860+
describe('no trailing entry row beside Add (objectstack#35507)', () => {
861+
function Stateful({ initial, f = field }: { initial: Record<string, unknown>[]; f?: any }) {
862+
const [rows, setRows] = React.useState(initial);
863+
return <GridField value={rows} onChange={setRows} field={f} />;
864+
}
865+
866+
it('a grid with lines draws exactly its lines, and the Add button', () => {
867+
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={field} />);
868+
expect(screen.getAllByLabelText('Description')).toHaveLength(1);
869+
expect(screen.getByTestId('line-items-add')).toBeTruthy();
870+
});
871+
872+
it('an empty grid draws no entry row, and names the Add button in its empty state', () => {
873+
render(<GridField value={[]} onChange={() => {}} field={field} />);
874+
expect(screen.queryAllByLabelText('Description')).toHaveLength(0);
875+
expect(screen.getByText('No items yet — click “Add line” to begin.')).toBeTruthy();
876+
});
877+
878+
it('CONTROL: with `allowAdd: false` there is neither an Add button nor an entry row, as before', () => {
879+
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={{ ...field, allowAdd: false }} />);
880+
expect(screen.queryByTestId('line-items-add')).toBeNull();
881+
expect(screen.getAllByLabelText('Description')).toHaveLength(1);
882+
});
883+
884+
it('CONTROL: an edit emits exactly the lines, with no blank line appended, as before', () => {
885+
const onChange = vi.fn();
886+
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={onChange} field={field} />);
887+
// `[0]`: the data line's cell, whatever else the grid draws below it.
888+
fireEvent.change(screen.getAllByLabelText('Description')[0], { target: { value: 'B' } });
889+
expect(onChange).toHaveBeenLastCalledWith([{ description: 'B', amount: 1 }]);
890+
});
891+
892+
it('Add moves focus into the new line, so the keyboard keeps typing', async () => {
893+
render(<Stateful initial={[{ description: 'A', amount: 1 }]} />);
894+
fireEvent.click(screen.getByTestId('line-items-add'));
895+
await waitFor(() => expect(screen.getAllByLabelText('Description')).toHaveLength(2));
896+
await waitFor(() => expect(document.activeElement).toBe(screen.getAllByLabelText('Description')[1]));
897+
});
898+
899+
it('Enter in the last line appends a line and moves to the same column in it', async () => {
900+
render(<Stateful initial={[{ description: 'A', amount: 1 }]} />);
901+
fireEvent.keyDown(screen.getByLabelText('Amount'), { key: 'Enter' });
902+
await waitFor(() => expect(screen.getAllByLabelText('Amount')).toHaveLength(2));
903+
await waitFor(() => expect(document.activeElement).toBe(screen.getAllByLabelText('Amount')[1]));
904+
});
905+
906+
it('CONTROL: Enter in the last line appends nothing when adding is off', () => {
907+
const onChange = vi.fn();
908+
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={onChange} field={{ ...field, allowAdd: false }} />);
909+
fireEvent.keyDown(screen.getByLabelText('Amount'), { key: 'Enter' });
910+
expect(onChange).not.toHaveBeenCalled();
911+
});
912+
});
913+
914+
/**
915+
* objectstack#35804 — each column header shows its field's help. A grid column
916+
* carries no field definition, so the host that holds the child object's
917+
* served definition (the one the record form reads, with other packages'
918+
* `fieldPatches` applied and the help in the reader's language) hands the
919+
* texts over through `columnHelpByField`, which reads each field through the
920+
* form's own `fieldHelpText`.
921+
*/
922+
describe('column header help (objectstack#35804)', () => {
923+
const help = { amount: 'Enter the tax-inclusive amount.' };
924+
925+
it('a column with help draws an info button whose accessible name is the help', () => {
926+
render(<GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />);
927+
const button = screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' });
928+
expect(button.closest('th')!.textContent).toContain('Amount');
929+
});
930+
931+
it('focusing the info button shows the help', async () => {
932+
render(<GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />);
933+
fireEvent.focus(screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' }));
934+
expect((await screen.findByRole('tooltip')).textContent).toBe('Enter the tax-inclusive amount.');
935+
});
936+
937+
it('the read-only table draws the same help', () => {
938+
render(<GridField value={[{ description: 'A', amount: 1 }]} onChange={() => {}} field={field} readonly columnHelp={help} />);
939+
expect(screen.getByRole('button', { name: 'Enter the tax-inclusive amount.' })).toBeTruthy();
940+
});
941+
942+
it('CONTROL: a column without help draws no info button', () => {
943+
render(<GridField value={[]} onChange={() => {}} field={field} columnHelp={help} />);
944+
const descriptionHeader = screen.getByText('Description').closest('th')!;
945+
expect(descriptionHeader.querySelector('button')).toBeNull();
946+
});
947+
948+
it('columnHelpByField reads each field the way the record form does', () => {
949+
expect(
950+
columnHelpByField({
951+
unit_price: { inlineHelpText: 'Inline help wins.', description: 'Not this.' },
952+
quantity: { description: 'The served description.' },
953+
notes: { inlineHelpText: '' },
954+
bad: null,
955+
}),
956+
).toEqual({ unit_price: 'Inline help wins.', quantity: 'The served description.' });
957+
expect(columnHelpByField(undefined)).toEqual({});
958+
});
959+
});

0 commit comments

Comments
 (0)