Skip to content

Commit 5533383

Browse files
fix(web): name combobox chip removal targets (pingdotgg#10127)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8268978 commit 5533383

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/web/src/components/ui/combobox.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,27 +352,37 @@ function ComboboxChips({
352352
}
353353

354354
function ComboboxChip({ children, ...props }: ComboboxPrimitive.Chip.Props) {
355+
const labelId = React.useId();
356+
355357
return (
356358
<ComboboxPrimitive.Chip
357359
className="flex items-center rounded-[calc(var(--radius-md)-1px)] bg-accent ps-2 font-medium text-accent-foreground text-sm outline-none sm:text-xs/(--text-xs--line-height) [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5"
358360
data-slot="combobox-chip"
359361
{...props}
360362
>
361-
{children}
362-
<ComboboxChipRemove />
363+
<span id={labelId}>{children}</span>
364+
<ComboboxChipRemove labelId={labelId} />
363365
</ComboboxPrimitive.Chip>
364366
);
365367
}
366368

367-
function ComboboxChipRemove(props: ComboboxPrimitive.ChipRemove.Props) {
369+
function ComboboxChipRemove({
370+
labelId,
371+
...props
372+
}: ComboboxPrimitive.ChipRemove.Props & { labelId: string }) {
373+
const removeLabelId = `${labelId}-remove`;
374+
368375
return (
369376
<ComboboxPrimitive.ChipRemove
370-
aria-label="Remove"
377+
aria-labelledby={`${removeLabelId} ${labelId}`}
371378
className="h-full shrink-0 cursor-pointer px-1.5 opacity-80 hover:opacity-100 [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5"
372379
data-slot="combobox-chip-remove"
373380
{...props}
374381
>
375-
<XIcon />
382+
<span id={removeLabelId} className="sr-only">
383+
Remove
384+
</span>
385+
<XIcon aria-hidden="true" />
376386
</ComboboxPrimitive.ChipRemove>
377387
);
378388
}

0 commit comments

Comments
 (0)