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

Commit 93a689d

Browse files
fix(components): the ui:select label names its combobox through htmlFor and the trigger id (objectui#10435) (#10548)
Fixes #10435 Clause-②: no ## What changed `ui:select` (`packages/components/src/renderers/form/select.tsx`) now writes `htmlFor={schema.id}` on its `Label` and `id={schema.id}` on the Radix `SelectTrigger`. This is the `record-picker-label-association-5771` shape the triage ruled. Before, neither end carried the wiring. The trigger is a `button` with `role="combobox"`, a role that takes no name from its content, so a labelled select's combobox had an empty accessible name. - A labelled select authored with an `id` is found by `getByRole('combobox', { name: 'Title' })`. - A required one's name stays `Title`: the objectui#10368 marker span is `aria-hidden`. - A select authored without an `id` mints none. Its caption stays unassociated, as on the sibling `input` / `textarea` renderers and `element:record_picker`. This half is pinned as deliberate. See Acceptance notes for the dispatch hypothesis it contradicts. ## Files (vs base `111fa4c`) | File | + / - | |---|---| | `packages/components/src/renderers/form/select.tsx` | +13 / -2 | | `packages/components/src/renderers/form/__tests__/select-label-association.test.tsx` (new, 7 cases) | +128 / -0 | | `packages/components/src/__tests__/required-marker-markup.test.tsx` | +3 / -5 | | `.changeset/10435-select-label-association.md` (`@object-ui/components` patch) | +20 / -0 | `required-marker-markup.test.tsx` is outside the claim's declared file surface. Its select site carried the comment "This label carries no `for` today", which this change made false. The comment is rewritten, and the locator becomes `label[for="sel-ctl"]`, the same form as the other five sites. ## Verification, on final head `4e99a54` (merge of `origin/main` `d461b0d`) - `pnpm exec vitest run packages/components/src/renderers/form/ packages/components/src/__tests__/required-marker-markup.test.tsx packages/components/src/__tests__/form-renderers.test.tsx` gave exit 0, with `Test Files 67 passed (67)` and `Tests 494 passed | 10 skipped (504)`. - `pnpm turbo run type-check --filter @object-ui/components --concurrency=2` gave exit 0 with `Tasks: 9 successful, 9 total`. It ran on `a75bf59`. The merge after that only touched `packages/app-shell`, `packages/plugin-dashboard`, `content/docs` and two changesets, all outside `@object-ui/components` and its `@object-ui/*` dependencies. `tsc -p tsconfig.test.json --listFilesOnly` lists both touched test files. - eslint on the 3 changed source and test files gave exit 0 with 0 errors and 4 warnings. All 4 warnings are pre-existing on the unchanged signature line, and the BASE `select.tsx` also shows 4. - These gates each gave exit 0: `check:control-bytes`, `check:test-path-roots`, `check:vi-mock-specifiers`, `check:vi-mock-inherit`, `check:vi-mock-override-shape`, `check:new-line-citations` (0 new), `check:changeset-claims`, `check:pending-changeset-literals`, `check-changeset-presence`, `check-changeset-no-major`, `check-changeset-overwrite`, `check-changeset-fixed`, `check-lint-coverage`. - NOT MEASURED: `check:sdui-registration-pins` exits 2 with a prerequisite refusal, because it needs a console build. This diff does not change the registration block. That gate is declared to CI. ## Reverse verification (ablation) The fix was committed first as `a75bf59`. The script then overwrote `select.tsx` with the BASE blob `4296933c`: `htmlFor={schema.id}` count went 1 to 0 on disk and `SelectTrigger id={schema.id}` count went 1 to 0. It ran the pin and `required-marker-markup.test.tsx`, then restored with `git checkout HEAD --` under an `EXIT INT TERM` trap. - Mutated run: exit 1, `Tests 8 failed | 14 passed (22)`. - 6 of the 7 new cases failed, starting with `Unable to find an accessible element with the role "combobox" and name "Title"`. - The no-`id` case stayed green, as expected. - Both select-site cases of `required-marker-markup` failed, because of the tightened `label[for]` locator. - Restore: file hash `8fc729cb` equals the HEAD blob, and `git diff HEAD` is empty. ## Acceptance notes - The dispatch's hypothesis H2 conflicts with the ruled shape. H2 said a select with no `schema.id` still needs a minted id, for example from `useId`. The ruled 5771 shape explicitly declines a `useId()` fallback, and its own test pins the no-`id` case as unassociated. The ruling was followed. The alternative is raised to the dispatching seat as an open question, not decided here. - Related to that question: the docs catalog examples `components-form-select/basic-select` and `components-form-input/with-label` author a `label` with no `id`. They render an unnamed control under the ruled shape. This is noted, not filed. Implementation session: `https://claude.ai/code/session_01KUxVUa7e39aNjhkKi1gsoy` (dispatched by the `domain:ui` seat 5). --- _Generated by [Claude Code](https://claude.ai/code/session_01KUxVUa7e39aNjhkKi1gsoy)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4a7ef0d commit 93a689d

4 files changed

Lines changed: 164 additions & 7 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
The `ui:select` form renderer's `label` now names its combobox (objectui#10435).
6+
7+
Before, the renderer drew its `Label` with no `htmlFor` and the Radix
8+
`SelectTrigger` with no `id`, and nothing set `aria-label` or
9+
`aria-labelledby`. The trigger is a `button` with `role="combobox"`, a role
10+
that takes no name from its content, so the placeholder and value text inside
11+
it did not name it either: a labelled select's combobox had an empty accessible
12+
name, and a screen reader announced an unnamed combobox.
13+
14+
The fix is the shape `element:record_picker` landed for the same defect
15+
(objectui#5771): the trigger gets the node's `id`, and the label gets `htmlFor`
16+
to it. A labelled select authored with an `id` is now named by its label, and a
17+
required one's name leaves out the `*`, because the required marker is an
18+
`aria-hidden` element (objectui#10368). A select authored without an `id`
19+
is unchanged: the renderer mints no id, so its caption stays unassociated, as
20+
on the sibling `input` and `textarea` renderers.

‎packages/components/src/__tests__/required-marker-markup.test.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ const SITES: Site[] = [
133133
required,
134134
options: [{ label: 'A', value: 'a' }],
135135
}),
136-
// This label carries no `for` today. Whether it SHOULD name the trigger is
137-
// outside objectui#10368 and deliberately not pinned either way here; the
138-
// marker must be an element regardless, because it would enter the name
139-
// the moment the label is associated.
140-
label: () => document.querySelector('label'),
136+
// The label names the trigger through `for` since objectui#10435, whose
137+
// own pin (`select-label-association.test.tsx`) reads the resulting name.
138+
label: () => document.querySelector('label[for="sel-ctl"]'),
141139
// Radix writes `aria-required` on the combobox trigger from `required`.
142140
expectRequiredState: () => expect(screen.getByRole('combobox')).toHaveAttribute('aria-required', 'true'),
143141
},
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
* `ui:select` — the authored `label` names the combobox (objectui#10435).
11+
*
12+
* Pre-fix, the renderer drew its `Label` with no `htmlFor` and the Radix
13+
* `SelectTrigger` with no `id`, and nothing set `aria-label` /
14+
* `aria-labelledby`. The trigger is a `button` with `role="combobox"`, a role
15+
* that takes no name from its content, so neither the placeholder nor the
16+
* value text named it: a labelled select's combobox had an EMPTY accessible
17+
* name, and `getByRole('combobox', { name: LABEL })` could not find it.
18+
*
19+
* The fix is the `element:record_picker` shape (objectui#5771): the trigger
20+
* gets `schema.id`, the label gets `htmlFor` to it. So every associated case
21+
* below authors an `id`, and the no-`id` case pins that the renderer mints
22+
* none, the same deliberate half that shape pins for the picker.
23+
*
24+
* Each case resolves the association end to end (`getByRole` by name,
25+
* `toHaveAccessibleName`, `label[for]` through `document.getElementById`, the
26+
* trigger's `labels` collection), never `htmlFor` and `id` read as two
27+
* independent strings: two values that are each present and never match is the
28+
* failure mode objectui#3341 documents.
29+
*/
30+
31+
import { describe, it, expect, afterEach } from 'vitest';
32+
import { render, screen, cleanup } from '@testing-library/react';
33+
import { SchemaRenderer } from '@object-ui/react';
34+
import { renderComponent } from '../../../__tests__/test-utils';
35+
// Registers `select` at module scope, not in a hook
36+
// (object-ui/no-dynamic-import-in-test-hook, objectui#3010).
37+
import '../../../renderers';
38+
39+
afterEach(cleanup);
40+
41+
const OPTIONS = [
42+
{ label: 'Mr', value: 'mr' },
43+
{ label: 'Ms', value: 'ms' },
44+
];
45+
46+
describe('ui:select — label names the combobox (objectui#10435)', () => {
47+
it('is found by getByRole combobox with the label as its name', () => {
48+
renderComponent({ type: 'select', id: 'title', label: 'Title', options: OPTIONS });
49+
50+
const combobox = screen.getByRole('combobox', { name: 'Title' });
51+
expect(combobox).toHaveAccessibleName('Title');
52+
expect(screen.getByLabelText('Title')).toBe(combobox);
53+
});
54+
55+
it('keeps the name `Title` when required: the aria-hidden marker stays out of it', () => {
56+
renderComponent({ type: 'select', id: 'title', label: 'Title', required: true, options: OPTIONS });
57+
58+
// The marker is still drawn inside the label (objectui#10368) ...
59+
const label = document.querySelector('label[for="title"]');
60+
expect(label).not.toBeNull();
61+
expect(label!.querySelector('[data-required-marker][aria-hidden="true"]')).toHaveTextContent('*');
62+
63+
// ... and the name the label now gives the combobox excludes it.
64+
const combobox = screen.getByRole('combobox', { name: 'Title' });
65+
expect(combobox).toHaveAccessibleName('Title');
66+
expect(combobox).toHaveAttribute('aria-required', 'true');
67+
});
68+
69+
it('points `for` at an id that really exists on the trigger', () => {
70+
renderComponent({ type: 'select', id: 'title', label: 'Title', options: OPTIONS });
71+
72+
const label = document.querySelector('label[for]');
73+
expect(label).not.toBeNull();
74+
const target = document.getElementById(label!.getAttribute('for')!);
75+
expect(target).not.toBeNull();
76+
expect(target).toBe(screen.getByRole('combobox'));
77+
78+
// The association browsers use for both the name and click-to-focus.
79+
const trigger = target as HTMLButtonElement;
80+
expect(Array.from(trigger.labels ?? [])).toEqual([label]);
81+
});
82+
83+
it('names the combobox with the label, not the placeholder text inside it', () => {
84+
renderComponent({ type: 'select', id: 'title', label: 'Title', placeholder: 'Choose…', options: OPTIONS });
85+
86+
const combobox = screen.getByRole('combobox');
87+
expect(combobox).toHaveTextContent('Choose…');
88+
expect(combobox).toHaveAccessibleName('Title');
89+
});
90+
91+
it('names the combobox with the label, not the selected value text inside it', () => {
92+
renderComponent({ type: 'select', id: 'title', label: 'Title', value: 'ms', options: OPTIONS });
93+
94+
const combobox = screen.getByRole('combobox');
95+
expect(combobox).toHaveTextContent('Ms');
96+
expect(combobox).toHaveAccessibleName('Title');
97+
});
98+
99+
it('mints no id when `schema.id` is absent: the caption stays unassociated', () => {
100+
// The deliberate half of the objectui#5771 shape: only the author supplies
101+
// `schema.id`, so without one the renderer neither writes `for` nor mints
102+
// an `id`, and the combobox stays unnamed, as before this change. Pinned so
103+
// a later change to that answer is a visible decision, not a drift.
104+
renderComponent({ type: 'select', label: 'Title', placeholder: 'Choose…', options: OPTIONS });
105+
106+
const combobox = screen.getByRole('combobox');
107+
expect(combobox).toHaveTextContent('Choose…');
108+
const label = document.querySelector('label');
109+
expect(label).not.toBeNull();
110+
expect(label).not.toHaveAttribute('for');
111+
expect(combobox).not.toHaveAttribute('id');
112+
expect(combobox).toHaveAccessibleName('');
113+
});
114+
115+
it('survives the real render path through SchemaRenderer', () => {
116+
render(
117+
<SchemaRenderer
118+
schema={{ type: 'select', id: 'title', label: 'Title', required: true, options: OPTIONS }}
119+
/>,
120+
);
121+
122+
// By role and name, not `getByLabelText('Title')`: that query matches the
123+
// label's whole text content, which on a required field includes the
124+
// aria-hidden `*` the accessible name leaves out.
125+
const combobox = screen.getByRole('combobox', { name: 'Title' }) as HTMLButtonElement;
126+
expect(Array.from(combobox.labels ?? [])).toEqual([document.querySelector('label[for="title"]')]);
127+
});
128+
});

‎packages/components/src/renderers/form/select.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ const SelectRenderer = ({ schema, className, onChange, value, disabled: hostDisa
4747
data-obj-type={dataObjType}
4848
style={style}
4949
>
50+
{/*
51+
The label names the trigger through a plain `htmlFor` / `id` pair on
52+
`schema.id` (objectui#10435), the shape `element:record_picker` landed
53+
for the same defect (objectui#5771): `SelectTrigger` renders a `button`
54+
with `role="combobox"`, a labelable element, and that role takes no
55+
name from its content, so without the pair the placeholder or value
56+
text inside it named nothing and the combobox's accessible name was
57+
empty. Only the author supplies `schema.id`, so a select authored
58+
without one keeps an unassociated caption, as on the sibling `input` /
59+
`textarea` renderers, rather than a minted `useId()` fallback.
60+
*/}
5061
{schema.label && (
51-
<Label className={cn(schema.required && "text-destructive")}>
62+
<Label htmlFor={schema.id} className={cn(schema.required && "text-destructive")}>
5263
{schema.label}
5364
{schema.required && (
5465
// A real `aria-hidden` element, not CSS generated content, the
@@ -72,7 +83,7 @@ const SelectRenderer = ({ schema, className, onChange, value, disabled: hostDisa
7283
name={schema.name}
7384
{...selectProps}
7485
>
75-
<SelectTrigger className={className}>
86+
<SelectTrigger id={schema.id} className={className}>
7687
<SelectValue placeholder={schema.placeholder} />
7788
</SelectTrigger>
7889
<SelectContent>

0 commit comments

Comments
 (0)