Skip to content

fix(Badge): make the dismiss control a real button - #1352

Open
chad-agent wants to merge 7 commits into
ClickHouse:mainfrom
chad-agent:chad/2026-12-02-badge-dismiss-button
Open

chad-agent wants to merge 7 commits into
ClickHouse:mainfrom
chad-agent:chad/2026-12-02-badge-dismiss-button

Conversation

@chad-agent

@chad-agent chad-agent commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

Keyboard users can now close a Badge.

  • The "x" on a dismissible Badge is a real button now. Tab reaches it, and screen readers call it "Close".
  • On keyboard focus, one round ring goes around the whole badge. It is easy to see on every badge color.
  • Inside MultiSelect, the "x" stays mouse-only, because those badges sit inside the MultiSelect button. Keyboard users remove a value from the list, as before.

Description

  • Badge renders the "x" as EmptyButton "Close" with a hidden icon. It was an svg image "close" that Tab skipped.
  • New closeElement?: 'button' | 'span' is for a badge inside a button. MultiSelectValue passes 'span' (hidden, no role or tabindex).
  • On keyboard focus, .wrapper draws one round ring (:has(.closebutton:focus-visible)); the button drops its own outline.

Links and tickets

  • Ports Badge from PR 1342 "feat!: migrate from Radix UI to UI SDK on React 19 (experiment)" by gjones (co-author).

Good to know

  • PR 1342's span (role="button", tabindex="-1") got axe nested-interactive and lost focus on click.
  • A ring on the "x" gave 1.10 to 2.03:1 on solid fills. Around the badge it is 3.84:1 light, 15.91:1 dark. Without :has() (Firefox 108 to 120) the button keeps the EmptyButton ring.
  • Caution: update tests that find the "x" by role img or name "close".

Checklist

  • Breaking changes? (add migration notes in changesets) No. The new prop is optional. The accessible name changes from "close" to "Close", and the role from image to button; the changeset says what to check.
  • Visual changes? (specify in changesets) Only on keyboard focus: one round ring around the whole badge. The resting look is unchanged (visual specs: 86 passed, 0 failed).
  • Design review needed? Yes, for the ring around the whole badge.

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook). Scripted Chromium checks on Storybook builds, listed under Accessibility. No hands-on pass in the Storybook UI.
  • build and build-storybook work locally
  • Tests and Stories are aligned with the changes. Tests yes. Stories unchanged: Badge still has no focus-visible story and no keyboard play.

Accessibility

  • Keyboard - every action works with Tab / Enter / Space / Esc; focus is visible and returns to the trigger on close. Tab reaches the Badge "Close" button (on main, Tab never reached the "x"), and Enter calls 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.
  • Names — every control has a name that includes its visible label; icon-only controls take aria-label. Button "Close"; the icon is hidden.
  • Vision — colors come from tokens, focus ring shows, targets are at least 24×24 px. Tokens and ring yes (3.84:1 light, 15.91:1 dark, 28 cases). The target is 12×12 px, the same icon box as on main, so 2.5.8 depends on the spacing exception, which I did not measure.

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 img or exact name "close".

Overview
Dismissible Badge controls are now a real Close button (via EmptyButton) instead of an icon with aria-label close, so Tab/Enter work and screen readers get a proper button name. The cross icon is decorative (aria-hidden).

New optional closeElement: default button; 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 passes closeElement: 'span' and keeps stopPropagation on onClose.

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.

chad-agent and others added 4 commits December 2, 2026 18:26
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-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5026833

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

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

@XOP XOP self-assigned this Dec 3, 2026
@XOP XOP added enhancement New feature or request a11y Accessibility improvements labels Dec 3, 2026
@XOP
XOP marked this pull request as ready for review December 3, 2026 16:52
Comment thread src/components/Badge/Badge.tsx Outdated
onClick={onClose}
className={styles.closebutton}
>
<Icon

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd set that icon to a variable instead of repeating the code twice.

@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 672 stories published Open Storybook
UI Tests ✅ 672 tests unchanged Open build

Built from commit: 9df063bf20eead2f6b2f2a8505f4a3ead8f915e4 · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/components/Badge/Badge.tsx Resolved

@DreaminDani DreaminDani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's two borders on focus? Can we stick with the one yellow outline? Also, ideally the outlines are totally rounded... But if that's not possible, OK.

CleanShot 2026-12-03 at 09 22 46

Comment thread src/components/Badge/Badge.module.css Outdated
align-items: center;
}

/* Two-color ring (WCAG technique C40). EmptyButton's outline sits on the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this comment?

chad-agent and others added 3 commits December 3, 2026 19:46
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 5026833. Configure here.

.closebutton:focus-visible {
outline: none;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5026833. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a11y Accessibility improvements enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants