Skip to content

Commit 1d37c02

Browse files
Fix Select component ARIA roles for Storybook tests
- Add role='listbox' to CommandList component in Select - Add role='option' to all CommandItem components (regular options and creatable options) - This ensures proper ARIA semantics for screen readers and test queries - Fixes failing CreatableOption test that was looking for listbox role The issue was that the Select component was using cmdk library components without explicit ARIA roles, causing tests to fail when querying for role='listbox' and role='option' elements.
1 parent 9df601e commit 1d37c02

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/components/src/ui/select.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function Select({
162162
/>
163163
</div>
164164
)}
165-
<CommandList id={listboxId} className="max-h-[200px] rounded-md w-full">
165+
<CommandList id={listboxId} role="listbox" className="max-h-[200px] rounded-md w-full">
166166
<CommandEmpty className="px-3 py-2 text-sm text-gray-500">No results.</CommandEmpty>
167167
<CommandGroup>
168168
{options.map((option, index) => {
@@ -185,6 +185,7 @@ export function Select({
185185
}}
186186
value={option.label}
187187
id={`${listboxId}-option-${index}`}
188+
role="option"
188189
{...commonProps}
189190
className={cn(itemClassName)}
190191
// Attach ref to CommandItem (even with asChild) so we can focus the selected item on open
@@ -210,6 +211,7 @@ export function Select({
210211
}}
211212
value={option.label}
212213
id={`${listboxId}-option-${index}`}
214+
role="option"
213215
{...commonProps}
214216
className={cn(
215217
'w-full text-left cursor-pointer select-none py-3 px-3 transition-colors duration-150 flex items-center gap-2 rounded',
@@ -240,6 +242,7 @@ export function Select({
240242
key={`__create__-${q}`}
241243
data-value={`__create__-${q}`}
242244
value={q}
245+
role="option"
243246
onSelect={async () => {
244247
if (!onCreateOption) return;
245248
const created = await onCreateOption(q);

0 commit comments

Comments
 (0)