Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 7d0c174

Browse files
fix(fields): name the boolean cell's read-only checkbox by its field (objectui#12584) (#12597)
Fixes #12584 Clause-②: no ## What changed The boolean cell renderer (`BooleanCellRenderer` in `packages/fields/src/index.tsx`) draws a plain read-only checkbox for every boolean column outside the completion and status names. That checkbox had no accessible name, so a screen reader announced each grid cell as a bare "checkbox, not checked", with no field. It is now named by the field: - One local value, `fieldLabel`: the field's label, else its humanized name. The off badge's text and the checkbox's `aria-label` both read it, so the expression is written once. - No state word in the name: the `checkbox` role announces checked or not checked itself. No new i18n key, no visual change (no class moved), no prop, export or type change. The `Checkbox` primitive is untouched. - The humanized fallback reads the field name as authored, not the lower-cased matching key (A3 below). Matching against the completion names and `STATUS_FIELD_NAMES` still uses the lower-cased key, unchanged. ## Mechanism assumptions, measured - **A1: the primitive forwards `aria-label` to the role element.** Holds. Every naming pin finds its box with `getByRole('checkbox', { name })`, which reads the name off the element that carries `role="checkbox"` (Radix's button), not off a wrapper. The source agrees: the `Checkbox` wrapper spreads its props onto `CheckboxPrimitive.Root`. - **A2: the grid hosts add no name of their own.** Holds, read from both hosts' cell wrappers. The data-table renderer draws `col.cell(...)` inside a `TableCell` and a `div` that carries only `className`, `title` and `data-auto-width-key`. `VirtualGrid` wraps it in a `div` with a class only. Neither sets `aria-labelledby` or `aria-label`, so nothing is named twice. The card's CDP reading (9 unnamed `checkbox` nodes) is the runtime face of the same fact. - **A3: `fieldName` is the lower-cased name.** True. `humanizeLabel` only capitalises the first letter of each word, so the lower-cased key read an unlabelled mixed-case name wrong. Measured on `humanizeLabel` itself (`packages/core/src/utils/humanize-label.ts`): | name | humanized as authored (now) | humanized lower-cased (before) | |---|---|---| | `IsPreferred` | `IsPreferred` | `Ispreferred` | | `is_preferred` | `Is Preferred` | `Is Preferred` | | `is_active` | `Is Active` | `Is Active` | | `IS_ACTIVE` | `IS ACTIVE` | `Is Active` | So the fallback now reads the name as authored, for the checkbox and the off badge alike, as the dispatch ruled. For every spec-legal name the words are byte-identical: the spec refuses an object field name that is not lowercase snake_case ("Field names must be lowercase snake_case"). The off badge's text moves only for an unlabelled, off-spec status name with an upper-case letter inside a word (for example `IS_ACTIVE`: "IS ACTIVE — Off", where it read "Is Active — Off"). `humanizeLabel` does not split camelCase, by its documented design, so `IsPreferred` reads `IsPreferred`, not "Is Preferred": the better of the two readings, not a perfect one. ## Tests New file `packages/fields/src/__tests__/booleanCell.accessibleName-12584.test.tsx`. It renders through `getCellRenderer(resolveCellRendererType(...))`, the way a grid host resolves a read-mode cell, for both `boolean` and `toggle`: - a labelled field, checked and unchecked: `getByRole('checkbox', { name: 'Preferred' })`; - an unlabelled field: the humanized name, `Is Preferred`; - an unlabelled mixed-case name: `IsPreferred` (A3); - a status field that is on (`is_active`, `true`): the box named `Active`, the measured HotCRM cell; - CONTROL: the completion indicator keeps "Completed" / "Not completed" and draws no checkbox; the off badge keeps "Active — Off" / "Is Active — Off" and draws no checkbox; a non-boolean value draws the `EmptyValue` affordance ("No value") and no checkbox. **Ablation.** The fix was committed first. The mutation went through `ablation-replace.mjs`, deleting ` aria-label={fieldLabel}`: anchor 1 to 0, blob `8d8a77e75ac8` to `433e77c56102`, on-disk count 0 inside the run. Result: `Tests 10 failed | 3 passed (13)`. All 10 naming pins went red with "Unable to find an accessible element with the role "checkbox" and name ...", and the 3 CONTROLs stayed green. Restore proven: blob equals HEAD `8d8a77e75ac8`, `git diff HEAD` empty. The test imports `../index` relatively, so the subject resolves to source, not `dist/`, and no rebuild was needed for the mutation to reach it. Runs, local, on a shared box, through the verify lock: - the new file: `Tests 13 passed (13)` at `63ba527469`; - every `packages/fields` suite named for boolean (5 files): `Tests 103 passed (103)` at `63ba527469`; - the whole `@object-ui/fields` suite: `Test Files 257 passed | 1 skipped (258)`, `Tests 4084 passed | 7 skipped (4091)` at `789a28d784`. The only later commit retypes the new test's render helper (`as any` to `as never`); - `pnpm --filter @object-ui/fields type-check`, after building its dependency closure (11 of 47 projects): exit 0 at `63ba527469`. `tsc -p tsconfig.test.json --listFiles` lists the new test file; - the census and ratchet sweep, the suites whose subject this diff touches (aria-label literal census, icon-only button census, machine-locale census, ellipsis glyph, emptiness floor, `humanizeLabel`, grid cell face label, detail section, widget DOM-leak sweep, catalog gallery render): `Test Files 10 passed (10)`, `Tests 878 passed (878)` at `789a28d784`. ## Gates Local subset at the final head `63ba527469`, each exit captured before any pipe: `check:control-bytes` 0, `check:new-line-citations` 0 (0 new citations), `check-changeset-presence` 0, `check-changeset-no-major` 0, `check-changeset-claims` 0, `check-governed-queue-guard --test` NOT GOVERNED. At `789a28d784`, also 0: `check-changeset-fixed`, `check-changeset-overwrite`, `check:pending-changeset-literals`, `check:i18n-keys`, `check:test-path-roots`, the three `check:vi-mock-*`, `check:comment-mask-corpus`, `check:shell-escape-residue`, `check-type-check-coverage`. ESLint on the two changed source files: 0 errors, no warning in the changed lines of `index.tsx`, none in the new test. The full farm is CI's. ## What the landing seat's browser reading should show HotCRM, the Account list (the runtime list grid; the Studio Records grid draws the same renderer), the `is_active` column. In the browser's accessibility tree (CDP `Accessibility.getFullAXTree`), each row whose `is_active` is true is a `checkbox` node, checked, named by the field's label: "Active" under en (HotCRM declares `label: 'Active'`), the translated column label under another locale. None has an empty name, and no name carries "Yes", "No", "true" or "false". Rows whose `is_active` is false still draw the destructive "Active — Off" badge, unchanged, and no checkbox. Any other boolean column outside the completion and status names reads the same way: one named checkbox per row. ## Acceptance notes - Observation, not filed (read from source, not reproduced in a browser): the data-table cell wrapper sets `title` to `String(cellValue)` for any non-object value, so hovering a boolean cell shows a raw `true` / `false` tooltip, in English under every locale. It does not name the checkbox: a `title` on an ancestor `div` is not part of the checkbox's name. Carrier: none. Session: `https://claude.ai/code/session_01JZnppgHRp4sREcouhkQYDB` --- _Generated by [Claude Code](https://claude.ai/code/session_01JZnppgHRp4sREcouhkQYDB)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f5eec63 commit 7d0c174

3 files changed

Lines changed: 140 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/fields': patch
3+
---
4+
5+
A boolean cell's read-only checkbox is named by its field (objectui#12584).
6+
7+
The boolean cell renderer draws a plain checkbox for every boolean column outside the completion and status names. It had no accessible name, so a screen reader announced each cell of the Studio Records grid and the runtime list grid as a bare "checkbox, not checked", with nothing to say which field it was. The checkbox is now named by the field's label, or by its humanized name when the field declares no label, the same words the status field's "Off" badge prints. The name carries no state word: the checkbox role announces checked or not checked itself.
8+
9+
The humanized-name fallback now reads the field name as authored, for the checkbox and the "Off" badge alike. It read the lower-cased name before, so an unlabelled `IsPreferred` read `Ispreferred`. A spec-legal field name is lowercase snake_case already, so for every such field the words are unchanged.
10+
11+
Nothing else moves: no visual change, no new language-pack key, and no export, prop or type member.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectui#12584 — the boolean cell's plain checkbox is named by its field.
11+
*
12+
* `BooleanCellRenderer` has three outcomes for a real boolean. Two already
13+
* named themselves: the completion indicator (`role="img"`, "Completed" /
14+
* "Not completed") and the status field's off badge ("LABEL — Off"). The
15+
* third, the plain read-only checkbox every other boolean column draws, had
16+
* no `aria-label`, no `aria-labelledby` and no text beside it, so a screen
17+
* reader announced each grid cell as a bare "checkbox, not checked" with no
18+
* field (measured on the Studio Records grid, HotCRM Account `is_active`).
19+
*
20+
* The name is the field's words, the ones the off badge already prints: its
21+
* label, else its humanized name. It carries no state word: the `checkbox`
22+
* role announces checked / not checked itself.
23+
*
24+
* Every naming case is found by `getByRole('checkbox', { name })`, so it reads
25+
* the name off the element that carries the role (Radix's button), not off a
26+
* wrapper. Every case renders through the registry exactly as a grid host
27+
* resolves a read-mode cell, for both types that map to this renderer.
28+
*
29+
* The CONTROL block pins what this change must leave alone: the completion
30+
* indicator's two names, the off badge's text, and the non-boolean
31+
* `EmptyValue` outcome with no checkbox in it.
32+
*/
33+
34+
import React from 'react';
35+
import { describe, it, expect, afterEach } from 'vitest';
36+
import { render, screen, cleanup } from '@testing-library/react';
37+
import '@testing-library/jest-dom';
38+
import { getCellRenderer, resolveCellRendererType } from '../index';
39+
40+
afterEach(() => cleanup());
41+
42+
const TYPES = ['boolean', 'toggle'] as const;
43+
44+
/** Resolve + render exactly the way a consumer builds a read-mode cell. */
45+
function renderCell(type: string, value: unknown, field: Record<string, unknown>) {
46+
const Renderer = getCellRenderer(resolveCellRendererType({ type }) || type);
47+
return render(<Renderer value={value} field={{ type, ...field } as never} />);
48+
}
49+
50+
describe('objectui#12584 — the boolean cell checkbox is named by its field', () => {
51+
for (const type of TYPES) {
52+
describe(`\`${type}\``, () => {
53+
it('a labelled field: a checked box is named by the label', () => {
54+
renderCell(type, true, { name: 'is_preferred', label: 'Preferred' });
55+
const box = screen.getByRole('checkbox', { name: 'Preferred' });
56+
expect(box).toBeChecked();
57+
});
58+
59+
it('a labelled field: an unchecked box is named by the label', () => {
60+
renderCell(type, false, { name: 'is_preferred', label: 'Preferred' });
61+
const box = screen.getByRole('checkbox', { name: 'Preferred' });
62+
expect(box).not.toBeChecked();
63+
});
64+
65+
it('an unlabelled field falls back to the humanized name', () => {
66+
renderCell(type, true, { name: 'is_preferred' });
67+
expect(screen.getByRole('checkbox', { name: 'Is Preferred' })).toBeChecked();
68+
});
69+
70+
it('an unlabelled mixed-case name keeps the spelling it was authored with', () => {
71+
// The renderer matches on the lower-cased name; the words it draws
72+
// read the name as authored, or this read `Ispreferred`.
73+
renderCell(type, false, { name: 'IsPreferred' });
74+
expect(screen.getByRole('checkbox', { name: 'IsPreferred' })).not.toBeChecked();
75+
});
76+
77+
it('a status field that is on draws the box, named by the label (the measured HotCRM `is_active` cell)', () => {
78+
renderCell(type, true, { name: 'is_active', label: 'Active' });
79+
expect(screen.getByRole('checkbox', { name: 'Active' })).toBeChecked();
80+
});
81+
});
82+
}
83+
});
84+
85+
describe('objectui#12584 — CONTROL: the outcomes that already named themselves are unchanged', () => {
86+
it('the completion indicator keeps its two names and draws no checkbox', () => {
87+
renderCell('boolean', true, { name: 'completed', label: 'Done?' });
88+
expect(screen.getByRole('img', { name: 'Completed' })).toBeInTheDocument();
89+
expect(screen.queryByRole('checkbox')).toBeNull();
90+
cleanup();
91+
92+
renderCell('boolean', false, { name: 'is_done' });
93+
expect(screen.getByRole('img', { name: 'Not completed' })).toBeInTheDocument();
94+
expect(screen.queryByRole('checkbox')).toBeNull();
95+
});
96+
97+
it('the off badge keeps its text and draws no checkbox', () => {
98+
const labelled = renderCell('boolean', false, { name: 'is_active', label: 'Active' });
99+
expect(labelled.getByTestId('boolean-warning-badge')).toHaveTextContent(/^Active — Off$/);
100+
expect(screen.queryByRole('checkbox')).toBeNull();
101+
cleanup();
102+
103+
const unlabelled = renderCell('boolean', false, { name: 'is_active' });
104+
expect(unlabelled.getByTestId('boolean-warning-badge')).toHaveTextContent(/^Is Active — Off$/);
105+
expect(screen.queryByRole('checkbox')).toBeNull();
106+
});
107+
108+
it('a non-boolean value draws the EmptyValue affordance and no checkbox', () => {
109+
const { container } = renderCell('boolean', 'true', { name: 'is_preferred', label: 'Preferred' });
110+
expect(screen.queryByRole('checkbox')).toBeNull();
111+
const empty = container.querySelector<HTMLElement>('[data-slot="empty-value"]');
112+
expect(empty, 'the shared EmptyValue affordance must be present').not.toBeNull();
113+
expect(empty?.getAttribute('aria-label')).toBe('No value');
114+
});
115+
});

‎packages/fields/src/index.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,14 @@ export function BooleanCellRenderer({ value, field }: CellRendererProps): React.
985985
const fieldName = field?.name?.toLowerCase() || '';
986986
const isCompletionField = fieldName === 'completed' || fieldName === 'is_completed'
987987
|| fieldName === 'done' || fieldName === 'is_done';
988+
// The field's words, ONE value read by both faces below that name the field
989+
// (objectui#12584): the off badge's text and the plain checkbox's accessible
990+
// name. Its label, else its humanized name. The fallback reads the name as
991+
// authored, not the lower-cased matching key above: `humanizeLabel` only
992+
// capitalises, so the key turned an unlabelled `IsPreferred` into
993+
// `Ispreferred`. A spec-legal name is lowercase snake_case already, so for
994+
// it the two spellings are the same string.
995+
const fieldLabel = field?.label || humanizeLabel(field?.name || '');
988996

989997
if (isCompletionField) {
990998
return (
@@ -1004,14 +1012,18 @@ export function BooleanCellRenderer({ value, field }: CellRendererProps): React.
10041012
if (STATUS_FIELD_NAMES.has(fieldName) && value === false) {
10051013
return (
10061014
<Badge variant="destructive" className="text-xs" data-testid="boolean-warning-badge">
1007-
{t('fields.boolean.offBadge', { label: field?.label || humanizeLabel(fieldName) })}
1015+
{t('fields.boolean.offBadge', { label: fieldLabel })}
10081016
</Badge>
10091017
);
10101018
}
10111019

10121020
return (
10131021
<div className="flex items-center justify-start">
1014-
<Checkbox checked={value} disabled className="pointer-events-none" />
1022+
{/* Named by the field (objectui#12584): with no name a screen reader
1023+
announced every cell as a bare "checkbox". The `checkbox` role
1024+
already announces checked / not checked, so the name carries no
1025+
state word. */}
1026+
<Checkbox checked={value} disabled aria-label={fieldLabel} className="pointer-events-none" />
10151027
</div>
10161028
);
10171029
}

0 commit comments

Comments
 (0)