Skip to content

Commit 6bc8529

Browse files
committed
wip(grid): narrow the held read-only answer; the changeset names the grid package (#35689)
Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1733276 commit 6bc8529

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
'@object-ui/components': patch
33
'@object-ui/i18n': patch
4+
'@object-ui/plugin-grid': patch
45
---
56

67
feat(components): in a list's grid a read-only cell says it is read-only, a cell save is said in one live region, and a touch never edits a cell in place
@@ -10,6 +11,6 @@ Metadata-protocol: none
1011

1112
The widening is additive: the new key `table.cellSavedAnnouncement` in every locale pack `@object-ui/i18n` publishes through `./locales`.
1213

13-
- **Read-only cells.** When the data table is a grid (`role="grid"`: a list page with the select-first cell model, or `keyboardNavigation`), a cell that opens no editor carries `aria-readonly="true"`, and so does the focus inside the selected cell, so a screen reader says "read only" on the cell it moves to. The selected cell reads the host's own facts (`GridCellSelection.describeCell`), the rest the table's own (`editable`, the column, the row). A plain table carries no `aria-readonly`.
14-
- **Save results.** A table that saves each cell (`GridCellSelection` with `onRowSave`) draws one visually hidden polite live region for its whole life and says each saved cell there, by column name ("Saved: Amount"; new pack key `table.cellSavedAnnouncement`, in all eleven locales). A refused save is said once, by the cell's existing alert. The cell's saving/saved mark is no longer a live region of its own (it was mounted with its words and announced unreliably); it stays a named image.
15-
- **Touch.** A tap on a cell that is not selected never edits in place: a lookup cell's edit button is not drawn for a finger, and a tap that lands on one drawn earlier for a mouse edits nothing. A tap still opens the record, which is where a touch edits.
14+
- **Read-only cells.** When the data table is a grid (`role="grid"`: a list page with the select-first cell model, or `keyboardNavigation`), a cell that opens no editor carries `aria-readonly="true"`, and so does the focus inside the selected cell, so a screen reader says "read only" on the cell it moves to. The selected cell adds the host's own facts (`GridCellSelection.describeCell`), asked as it becomes selected and again only when the row is re-read or the host hands a new value, never on each render; the rest read the table's own (`editable`, the column, the row). A plain table carries no `aria-readonly`. In a list, an approval lock or an update verdict that answers after the cell was selected is said on that cell at once, without the reader moving: the lock read re-renders the grid when it answers, and the grid hands the table a new value only when what its cell facts read changed.
15+
- **Save results.** A table that saves each cell (`GridCellSelection` with `onRowSave`) draws one visually hidden polite live region for its whole life and says each saved cell there, by column name ("Saved: Amount"; new pack key `table.cellSavedAnnouncement`, in all eleven locales). Cells saved together are joined in the locale's list punctuation (`validation.formInvalidJoiner`: `、` in ja and zh); a column with no header is never named by its key (the region says "Saved"). A refused save is said once, by the cell's existing alert. The cell's saving/saved mark is no longer a live region of its own (it was mounted with its words and announced unreliably); it stays a named image.
16+
- **Touch.** A tap on a cell that is not selected never edits in place: a lookup cell's edit button is not drawn for a finger, and a tap that lands on one drawn earlier for a mouse does nothing (the row ignores a click on a button). A tap elsewhere on the cell still opens the record, which is where a touch edits. A later click on the button with no pointer of its own (assistive tech) edits as before.

‎ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function schemaOf(onRowSave: Save, extra: Record<string, unknown> = {}) {
8282

8383
function renderTable(onRowSave: Save, extra: Record<string, unknown> = {}, withProvider = true, language?: string) {
8484
const DataTable = ComponentRegistry.get('data-table')!;
85-
const table = (schema: any) => (withProvider
85+
const table = (schema: Record<string, unknown>) => (withProvider
8686
? <GridCellSelectionProvider value={{}}><DataTable schema={schema} /></GridCellSelectionProvider>
8787
: <DataTable schema={schema} />);
8888
const tree = (schema: any) => (language

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,13 +3736,15 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
37363736
// was waiting on arrived). Never asked per render; every render reads this.
37373737
const selectedRow = selectedPos ? paginatedData[selectedPos.rowIndex] : undefined;
37383738
const selectedColumnKey = selectedPos ? columns[selectedPos.colIndex].accessorKey : undefined;
3739-
const [selectedHostReadOnly, setSelectedHostReadOnly] = useState<{ row: any; columnKey: string } | null>(null);
3739+
const [selectedHostReadOnly, setSelectedHostReadOnly] = useState<{ row: unknown; columnKey: string } | null>(null);
37403740
useLayoutEffect(() => {
37413741
const readOnly = selectedRow !== undefined && selectedColumnKey !== undefined
37423742
&& !!cellSelection?.describeCell?.(selectedRow, selectedColumnKey)?.readOnlyReason;
37433743
setSelectedHostReadOnly((prev) => {
3744-
if (!readOnly) return null;
3745-
return prev?.row === selectedRow && prev.columnKey === selectedColumnKey ? prev : { row: selectedRow, columnKey: selectedColumnKey! };
3744+
if (!readOnly || selectedColumnKey === undefined) return null;
3745+
return prev !== null && prev.row === selectedRow && prev.columnKey === selectedColumnKey
3746+
? prev
3747+
: { row: selectedRow, columnKey: selectedColumnKey };
37463748
});
37473749
}, [selectedRow, selectedColumnKey, cellSelection]);
37483750
const setSelectedCell = (pos: { rowIndex: number; colIndex: number } | null) =>
@@ -5218,8 +5220,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
52185220
// reader moves to) adds the host's, asked when it became selected
52195221
// (`selectedHostReadOnly`: `describeCell` is never asked per render).
52205222
const cellReadOnly = keyboardNavigation
5221-
&& (!isEditable || (isSelectedCell && selectedHostReadOnly?.row === row
5222-
&& selectedHostReadOnly.columnKey === col.accessorKey));
5223+
&& (!isEditable || (isSelectedCell && selectedHostReadOnly !== null
5224+
&& selectedHostReadOnly.row === row && selectedHostReadOnly.columnKey === col.accessorKey));
52235225
// What the cell draws; the preview layer draws the same, unclipped.
52245226
const drawCell = (): React.ReactNode => (typeof col.cell === 'function'
52255227
? col.cell(cellValue, row)

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,9 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
13791379
// what this render holds through `latestCellHooks`.
13801380
const gridEditable = schema.editable ?? false;
13811381
const latestCellHooks = React.useRef({ requiredPrompt, askStateMove, openReferencedRecord });
1382-
latestCellHooks.current = { requiredPrompt, askStateMove, openReferencedRecord };
1382+
React.useLayoutEffect(() => {
1383+
latestCellHooks.current = { requiredPrompt, askStateMove, openReferencedRecord };
1384+
});
13831385
const opensReferencedRecords = !!openReferencedRecord;
13841386
const gridCellSelection = useMemo((): GridCellSelection | null => (hostCellSelection
13851387
? {

0 commit comments

Comments
 (0)