Repository navigation
fix(Badge): make the dismiss control a real button - #1352
chad-agent wants to merge 7 commits into
Conversation
The dismiss "x" was an svg with a click handler: Tab never reached it and it was exposed as an image named "close". It is now an EmptyButton named "Close" with a decorative icon. A new closeElement="span" keeps MultiSelect's badges free of a nested button. Ported from PR 1342. The icon gets aria-hidden explicitly, because main's Icon has no decorative default yet. Co-authored-by: Gareth Jones <305167+gjones@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inside the MultiSelect trigger button, the span had role="button" and tabindex="-1". axe flags that as nested-interactive, and a click moved focus to the span, which then unmounted and left focus on the body. The span is now aria-hidden with no role, tabindex or label. A click leaves focus on the trigger, and the listbox stays the keyboard path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EmptyButton's outline sits on the badge fill. On solid badges that gave 1.10 to 2.03:1, under the 3:1 of WCAG 1.4.11. A 2px band of the page background between the button and the outline (a two-color ring, WCAG technique C40) keeps the ring at 3.84:1 in light and 15.4:1 in dark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 5026833 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| onClick={onClose} | ||
| className={styles.closebutton} | ||
| > | ||
| <Icon |
There was a problem hiding this comment.
I'd set that icon to a variable instead of repeating the code twice.
Chromatic Storybook
Built from commit: Statuses as of the end of the run. The build link shows the live review state. |
| align-items: center; | ||
| } | ||
|
|
||
| /* Two-color ring (WCAG technique C40). EmptyButton's outline sits on the |
There was a problem hiding this comment.
do we need this comment?
Both dismiss variants rendered the same cross icon. It is now one variable, as asked in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review asked for one outline instead of the two-color ring, ideally round. The ring now goes around the whole badge pill, which is round. It sits on the page background, so it keeps 3:1 on every badge fill (3.84:1 light, 15.91:1 dark). Without :has() support, the button keeps the EmptyButton ring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 5026833. Configure here.
| .closebutton:focus-visible { | ||
| outline: none; | ||
| } | ||
| } |
There was a problem hiding this comment.
Fallback focus ring fails contrast
Medium Severity
The C40 box-shadow band that lifted contrast on solid fills is gone. Browsers that skip the :has() block keep only EmptyButton's outline, which measured 1.10–2.03:1. That path is still in .browserslistrc (last 4 years; the comment names Firefox 108–120), so the 3:1 claim does not hold there.
Reviewed by Cursor Bugbot for commit 5026833. Configure here.



TL;DR
Keyboard users can now close a Badge.
Description
Badgerenders the "x" asEmptyButton"Close" with a hidden icon. It was an svg image "close" that Tab skipped.closeElement?: 'button' | 'span'is for a badge inside a button.MultiSelectValuepasses'span'(hidden, no role or tabindex)..wrapperdraws one round ring (:has(.closebutton:focus-visible)); the button drops its own outline.Links and tickets
Good to know
role="button",tabindex="-1") got axenested-interactiveand lost focus on click.:has()(Firefox 108 to 120) the button keeps the EmptyButton ring.imgor name "close".Checklist
Contribution
buildandbuild-storybookwork locallyplay.Accessibility
onClose(Space not tested on its own; Esc does not apply). In MultiSelect, the trigger stays the only Tab stop, and a click on the "x" keeps focus on the trigger.aria-label. Button "Close"; the icon is hidden.WCAG 2.2 criteria checked: 2.1.1 Keyboard, 4.1.2 Name, Role, Value, 2.4.7 Focus Visible, 1.4.11 Non-text Contrast, 2.4.3 Focus Order (focus after a click on the MultiSelect "x").
Tested: Chromium 159 (Playwright image v1.65.1) and axe-core 4.11.1 on Storybook builds of main 5615df2 and this branch. 26 Badge stories and 7 MultiSelect stories, light and dark, MultiSelect closed and open. axe: 0 violations added.
Not tested: Firefox, Safari, forced colors, screen readers.
Screenshots
None attached.
🤖 Generated with Claude Code
Note
Low Risk
Localized UI/accessibility change with an optional prop; assistive name/role changed from image "close" to button "Close", which may break tests that query by
imgor exact name "close".Overview
Dismissible Badge controls are now a real Close button (via
EmptyButton) instead of an icon witharia-labelclose, so Tab/Enter work and screen readers get a proper button name. The cross icon is decorative (aria-hidden).New optional
closeElement: defaultbutton; use'span'when the badge lives inside another button (e.g. MultiSelect trigger). The span dismiss control is pointer-only,aria-hidden, and not in the tab order—keyboard removal stays on the listbox. MultiSelectValue passescloseElement: 'span'and keepsstopPropagationononClose.Focus styling: when the close button has
:focus-visible, a single outline wraps the whole badge (:wrapper:has(.closebutton:focus-visible)) for ≥3:1 contrast on all badge types; browsers without:has()fall back to EmptyButton’s ring.Tests cover button role/name, keyboard
onClose,closeElement="span"behavior, and MultiSelect badge dismiss without nested tab stops.Reviewed by Cursor Bugbot for commit 5026833. Bugbot is set up for automated code reviews on this repo. Configure here.