Skip to content

Commit 460a603

Browse files
authored
fix(a11y): add accessible labels to icon-only controls (#50)
1 parent 2682319 commit 460a603

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.changeset/odd-states-attend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
fix(a11y): add accessible labels to icon-only controls

packages/kumo/src/components/combobox/combobox.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,20 @@ const triggerInputIconStyles: Record<
308308
},
309309
};
310310

311-
function TriggerInput(props: ComboboxBase.Input.Props) {
311+
function TriggerInput({
312+
clearLabel = "Clear selection",
313+
showOptionsLabel = "Show options",
314+
...props
315+
}: ComboboxBase.Input.Props & {
316+
/** Accessible label for the clear button. Pass a translated string for i18n.
317+
* @default "Clear selection"
318+
*/
319+
clearLabel?: string;
320+
/** Accessible label for the dropdown trigger. Pass a translated string for i18n.
321+
* @default "Show options"
322+
*/
323+
showOptionsLabel?: string;
324+
}) {
312325
const size = useContext(ComboboxSizeContext);
313326
const iconStyles = triggerInputIconStyles[size];
314327

@@ -331,6 +344,7 @@ function TriggerInput(props: ComboboxBase.Input.Props) {
331344
/>
332345

333346
<ComboboxBase.Clear
347+
aria-label={clearLabel}
334348
className={cn(
335349
"absolute top-1/2 flex -translate-y-1/2 cursor-pointer bg-transparent p-0",
336350
"data-[disabled]:pointer-events-none data-[disabled]:opacity-0",
@@ -341,6 +355,7 @@ function TriggerInput(props: ComboboxBase.Input.Props) {
341355
</ComboboxBase.Clear>
342356

343357
<ComboboxBase.Trigger
358+
aria-label={showOptionsLabel}
344359
className={cn(
345360
"absolute top-1/2 -translate-y-1/2 flex items-center justify-center cursor-pointer text-kumo-subtle",
346361
"m-0 bg-transparent p-0", // Reset Stratus global button styles
@@ -430,7 +445,15 @@ function Group(props: ComboboxBase.Group.Props) {
430445
);
431446
}
432447

433-
function Chip(props: ComboboxBase.Chip.Props) {
448+
function Chip({
449+
removeLabel = "Remove",
450+
...props
451+
}: ComboboxBase.Chip.Props & {
452+
/** Accessible label for the chip remove button. Pass a translated string for i18n.
453+
* @default "Remove"
454+
*/
455+
removeLabel?: string;
456+
}) {
434457
return (
435458
<ComboboxBase.Chip
436459
{...props}
@@ -444,6 +467,7 @@ function Chip(props: ComboboxBase.Chip.Props) {
444467
>
445468
{props.children}
446469
<ComboboxBase.ChipRemove
470+
aria-label={removeLabel}
447471
className={cn(
448472
"cursor-pointer rounded-md p-1 hover:bg-kumo-fill-hover",
449473
"bg-transparent flex",

packages/kumo/src/components/menubar/menubar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const MenuOption = ({
4444
}: MenuOptionProps) => {
4545
const button = (
4646
<button
47+
aria-label={tooltip}
4748
className={cn(
4849
"focus:inset-ring-focus relative -ml-px flex h-full w-11 cursor-pointer items-center justify-center rounded-md border-none bg-kumo-elevated first:rounded-l-lg last:rounded-r-lg transition-colors focus:z-1 focus:outline-none focus-visible:z-1 focus-visible:inset-ring-[0.5]",
4950
{

0 commit comments

Comments
 (0)