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

Commit c14d3a0

Browse files
os-justinclaude
andauthored
fix(components): combobox honours options[].disabled (#8142)
* fix(components): combobox honours options[].disabled `options[].disabled` was declared by `@object-ui/types` and validated by the zod mirror, but `Combobox` never read it: each option became a `CommandItem` carrying `key`, `value` and `onSelect` only, so an option authored `disabled: true` passed validation, type-checked against the published `ComboboxSchema`, and rendered as an ordinary selectable option. The component now sets `disabled={option.disabled}`, the spelling the sibling select renderer already uses on `SelectItem`. cmdk 1.1.1 needs nothing more: a disabled `Command.Item` renders with `onClick` undefined, never registers the `cmdk-item-select` listener Enter dispatches, and is excluded from the valid-item selector the arrow keys walk — so a refusal inside `onSelect` would have been unreachable code. Measured, not assumed. The pin asserts both halves, because an attribute-only pin passes on "styled disabled but still clickable": the option carries `data-disabled` / `aria-disabled`, AND neither a click nor Enter fires `onValueChange`. Two control legs keep those negatives from being vacuous. Also refreshes the `ComboboxOption` block in the combobox docs page, which still documented the shape as `{ value; label }`. It sits in a plaintext fence, so no docs gate reads it. Refs: objectui#7687 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S * test(types): claim the new combobox disabled row in the docs census `component-docs-disabled-inherited-7239.test.ts` is a census over `content/docs/components`: it classifies every documented `disabled?:` row as INHERITED or INDEPENDENT and pins the population by measurement. Documenting `ComboboxOption.disabled` adds a real 23rd row, so the census failed with the row unclassified and the population one short. The row is claimed as INDEPENDENT on the file's own stated criterion, not by bumping the count: the shipped `ComboboxOption` declares `disabled` itself and does NOT extend `BaseSchema`, so the narrow `boolean` spelling on the page is the correct one and the second INDEPENDENT assertion holds for it unchanged. Counts move consistently — rows 22 to 23, independent 8 to 9, inherited unchanged at 14. A new `## Amendments` section records why the ledger moved, so a later reader can tell a deliberate claim from a number someone bumped to get back to green. It also corrects a belief the #7687 card recorded: the page's `plaintext` fence does keep the doc-TYPE gates from reading it, but this census reads the `.mdx` files as text, so a docs edit under `content/docs/components` that touches a `disabled` row is answerable to `packages/types`. Refs: objectui#7687 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 21d7989 commit c14d3a0

5 files changed

Lines changed: 194 additions & 1 deletion

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
'@object-ui/components': minor
3+
---
4+
5+
Honour `options[].disabled` on a `combobox` node (objectui#7687).
6+
7+
**User-visible behaviour change, deliberately — hence `minor`, not `patch`.** The
8+
member was already declared by `@object-ui/types` (`ComboboxOption.disabled`) and
9+
already validated by the zod mirror (`ComboboxOptionSchema`, pinned as `boolean`
10+
on both faces by the objectui#7087 twin-symmetry ruling), but the component never
11+
read it: `Combobox` mapped each option to a `CommandItem` carrying `key`, `value`
12+
and `onSelect` only. So an option authored `{ value, label, disabled: true }`
13+
passed `safeValidateSchema`, type-checked against the published `ComboboxSchema`,
14+
and then rendered as an ordinary, fully selectable option — a declared key with no
15+
read site behind it, the class the enforce-or-remove ledgers exist to close.
16+
17+
An author who already writes `disabled: true` today gets a different combobox
18+
after this change: that option now renders dimmed and can no longer be chosen, by
19+
click or by keyboard. That is the intended repair — declared and validated should
20+
mean enforced — but it is a change in what existing metadata does, not a silent
21+
internal fix, so it is priced as a behaviour change rather than a patch.
22+
23+
The alternative remedy, retiring `disabled` from `ComboboxOption` and the zod
24+
mirror, was weighed and **not** adopted: it narrows a published surface and would
25+
require the objectui#7087 twin-symmetry pin to be changed, where honouring the key
26+
restores declared = enforced at the cost of one prop. The spelling follows the
27+
sibling select renderer, which already sets `disabled={opt.disabled}` on its
28+
`SelectItem`.
29+
30+
Nothing else moves. The whole-control `disabled` prop (the one forwarded to the
31+
trigger button) is untouched, no key is added to `@object-ui/types`, and no new
32+
key is introduced — this release only starts reading one that was already
33+
published.
34+
35+
`@object-ui/types` is deliberately **not** given its own bump. The one file that
36+
changes there is a test, `component-docs-disabled-inherited-7239.test.ts`: its
37+
census over `content/docs/components` counts every documented `disabled?:` row,
38+
and documenting the member adds a legitimate row that the ledger now claims as
39+
INDEPENDENT (the shipped `ComboboxOption` declares `disabled` itself and does not
40+
extend `BaseSchema`, so the narrow `boolean` spelling is correct for it). No
41+
shipped type or value moves in that package, so there is no behaviour there to
42+
version.

‎content/docs/components/form/combobox.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The Combobox component combines a text input with a dropdown list, allowing user
2828
interface ComboboxOption {
2929
value: string;
3030
label: string;
31+
disabled?: boolean; // Option renders dimmed and cannot be selected
3132
}
3233
3334
interface ComboboxSchema {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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#7687 — `options[].disabled` on a `combobox` node must be READ.
11+
*
12+
* The member was declared (`@object-ui/types` `ComboboxOption.disabled`),
13+
* validated (`ComboboxOptionSchema` in the zod mirror, pinned as `boolean` on
14+
* both faces by `disabled-twin-symmetry-7087.test.ts`) and never read: the
15+
* component mapped each option to a `CommandItem` with `key` / `value` /
16+
* `onSelect` only, so an option authored `disabled: true` passed validation,
17+
* type-checked against the published `ComboboxSchema`, and rendered as an
18+
* ordinary selectable option — a declared key with no read site behind it.
19+
*
20+
* ⛔ An attribute-only pin is not enough here: it passes on "styled disabled
21+
* but still clickable", which is the exact defect this card is about. So the
22+
* behaviour is pinned too — a disabled option must not fire `onValueChange`.
23+
* The third test is the CONTROL that keeps that negative from being vacuous:
24+
* without it, a popover that never opened would satisfy "not called".
25+
*/
26+
import { describe, it, expect, vi } from 'vitest';
27+
import React from 'react';
28+
import { render, screen, fireEvent } from '@testing-library/react';
29+
import '@testing-library/jest-dom';
30+
import { Combobox } from '../custom/combobox';
31+
32+
const OPTIONS = [
33+
{ value: 'alpha', label: 'Alpha' },
34+
{ value: 'beta', label: 'Beta', disabled: true },
35+
{ value: 'gamma', label: 'Gamma', disabled: false },
36+
];
37+
38+
function openDropdown() {
39+
fireEvent.click(screen.getByRole('combobox'));
40+
}
41+
42+
describe('Combobox honours options[].disabled (objectui#7687)', () => {
43+
it('marks an option authored `disabled: true` as disabled in the DOM', () => {
44+
render(<Combobox options={OPTIONS} value="" onValueChange={vi.fn()} />);
45+
openDropdown();
46+
47+
const beta = screen.getByRole('option', { name: /Beta/ });
48+
// `data-disabled` is what the CommandItem wrapper's className already
49+
// styles (`data-[disabled=true]:opacity-50 …:pointer-events-none`);
50+
// `aria-disabled` is what assistive tech and cmdk's own valid-item
51+
// selector read.
52+
expect(beta).toHaveAttribute('data-disabled', 'true');
53+
expect(beta).toHaveAttribute('aria-disabled', 'true');
54+
});
55+
56+
it('refuses to select a disabled option — no onValueChange', () => {
57+
const onValueChange = vi.fn();
58+
render(<Combobox options={OPTIONS} value="" onValueChange={onValueChange} />);
59+
openDropdown();
60+
61+
fireEvent.click(screen.getByRole('option', { name: /Beta/ }));
62+
expect(onValueChange).not.toHaveBeenCalled();
63+
});
64+
65+
it('refuses the keyboard path too — Enter on a search narrowed to the disabled option selects nothing', () => {
66+
const onValueChange = vi.fn();
67+
render(<Combobox options={OPTIONS} value="" onValueChange={onValueChange} />);
68+
openDropdown();
69+
70+
// A separate code path from the click above: cmdk keeps disabled items out
71+
// of the valid-item selector its arrow keys and its auto-select walk, and
72+
// never registers the `cmdk-item-select` listener Enter dispatches. With
73+
// the list narrowed to `Beta` alone there is nothing left to select.
74+
const search = screen.getByPlaceholderText('Search...');
75+
fireEvent.change(search, { target: { value: 'bet' } });
76+
expect(screen.getByRole('option', { name: /Beta/ })).toBeInTheDocument();
77+
expect(screen.queryByRole('option', { name: /Alpha/ })).toBeNull();
78+
79+
fireEvent.keyDown(search, { key: 'Enter' });
80+
expect(onValueChange).not.toHaveBeenCalled();
81+
});
82+
83+
it('CONTROL — options without `disabled: true` stay selectable', () => {
84+
const onValueChange = vi.fn();
85+
render(<Combobox options={OPTIONS} value="" onValueChange={onValueChange} />);
86+
openDropdown();
87+
88+
// Omitted (`alpha`) and explicitly `false` (`gamma`) are both enabled.
89+
const alpha = screen.getByRole('option', { name: /Alpha/ });
90+
const gamma = screen.getByRole('option', { name: /Gamma/ });
91+
expect(alpha).toHaveAttribute('data-disabled', 'false');
92+
expect(gamma).toHaveAttribute('data-disabled', 'false');
93+
94+
fireEvent.click(alpha);
95+
expect(onValueChange).toHaveBeenCalledWith('alpha');
96+
});
97+
98+
it('CONTROL — the keyboard path still selects an enabled option', () => {
99+
const onValueChange = vi.fn();
100+
render(<Combobox options={OPTIONS} value="" onValueChange={onValueChange} />);
101+
openDropdown();
102+
103+
const search = screen.getByPlaceholderText('Search...');
104+
fireEvent.change(search, { target: { value: 'gam' } });
105+
fireEvent.keyDown(search, { key: 'Enter' });
106+
expect(onValueChange).toHaveBeenCalledWith('gamma');
107+
});
108+
});

‎packages/components/src/custom/combobox.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ export function Combobox({
115115
<CommandItem
116116
key={option.value}
117117
value={option.value}
118+
// objectui#7687 — `options[].disabled` is declared by
119+
// `@object-ui/types` and validated by the zod mirror, so it
120+
// has to be READ; the sibling select renderer already spells
121+
// it this way (`disabled={opt.disabled}` on `SelectItem`).
122+
// cmdk 1.1.1 needs nothing more than the prop: a disabled
123+
// `Command.Item` renders with `onClick` undefined, never
124+
// registers the `cmdk-item-select` listener Enter
125+
// dispatches, and is excluded from the valid-item selector
126+
// the arrow keys walk — so an extra refusal inside
127+
// `onSelect` below would be unreachable. Measured, and the
128+
// behaviour half of `combobox-option-disabled.test.tsx`
129+
// keeps that measurement honest.
130+
disabled={option.disabled}
118131
onSelect={(currentValue) => {
119132
onValueChange?.(currentValue === value ? "" : currentValue)
120133
setOpen(false)

‎packages/types/src/__tests__/component-docs-disabled-inherited-7239.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@
7878
* That last pair is the point of the control: a failure that reddened the
7979
* independent rows too would mean the sweep was indiscriminate, not that the
8080
* inherited rows were wrong.
81+
*
82+
* ## Amendments
83+
*
84+
* The population is a ledger, not a constant: it moves when a page gains or
85+
* loses a real `disabled` row. Each move is recorded here with its cause, so a
86+
* later reader can tell a deliberate claim from a number someone bumped to get
87+
* back to green.
88+
*
89+
* - **22 -> 23 rows, INDEPENDENT 8 -> 9 (objectui#7687).** `ComboboxOption`
90+
* joins the independent table. Its `disabled` was always DECLARED by
91+
* `packages/types/src/form.ts` and validated by `ComboboxOptionSchema`, but
92+
* the combobox component never read it, so an option authored
93+
* `disabled: true` rendered selectable; #7687 makes the component honour it
94+
* and documents the member on `form/combobox.mdx`, which is the row this
95+
* census then measured. It classifies INDEPENDENT on this file's own
96+
* criterion, not by resemblance to its neighbours: the shipped
97+
* `ComboboxOption` declares `disabled` itself and does NOT extend
98+
* `BaseSchema`, so the narrow `boolean` is the correct spelling and the
99+
* second INDEPENDENT assertion holds for it unchanged.
100+
*
101+
* ⚠️ Note for the class, since the #7687 card recorded the opposite: that
102+
* page's `interface` block sits in a `plaintext` fence and the card
103+
* concluded no CI gate could see it. True of the doc-type gates named
104+
* above, and false overall — THIS census reads those `.mdx` files as text
105+
* and caught the new row. A doc edit under `content/docs/components` that
106+
* touches a `disabled` row is answerable to `packages/types`, so a run
107+
* narrowed to the package the code fix lives in cannot see it.
81108
*/
82109

83110
import { describe, expect, it } from 'vitest';
@@ -184,6 +211,8 @@ const INDEPENDENT = [
184211
{ page: 'basic/button-group.mdx', iface: 'ButtonGroupButton', shippedName: 'ButtonGroupButton' },
185212
{ page: 'disclosure/accordion.mdx', iface: 'AccordionItem', shippedName: 'AccordionItem' },
186213
{ page: 'disclosure/toggle-group.mdx', iface: 'ToggleGroupItem', shippedName: 'ToggleGroupItem' },
214+
// Added by objectui#7687, which made the member real — see `## Amendments`.
215+
{ page: 'form/combobox.mdx', iface: 'ComboboxOption', shippedName: 'ComboboxOption' },
187216
{ page: 'form/form.mdx', iface: 'FormField', shippedName: 'FormField' },
188217
{ page: 'form/radio-group.mdx', iface: 'RadioOption', shippedName: 'RadioOption' },
189218
// Doc-local names; the shipped shape they illustrate is `MenuCommandItem`.
@@ -246,7 +275,7 @@ describe('the two tables account for every documented `disabled` row (objectui#7
246275

247276
it('sees exactly the population this card measured', () => {
248277
expect({ rows: ROWS.length, inherited: INHERITED.length, independent: INDEPENDENT.length }).toEqual(
249-
{ rows: 22, inherited: 14, independent: 8 },
278+
{ rows: 23, inherited: 14, independent: 9 },
250279
);
251280
});
252281
});

0 commit comments

Comments
 (0)