feat(components): add selected icon to ToggleButton - #2017
Draft
ShreyasGit51283 wants to merge 1 commit into
Draft
feat(components): add selected icon to ToggleButton#2017ShreyasGit51283 wants to merge 1 commit into
ShreyasGit51283 wants to merge 1 commit into
Conversation
A selected toggle button now shows check-circle, so selection reads at a glance rather than from the border and fill alone. When a button has a leading icon, selecting it swaps that icon for the selected one instead of showing both. The elevated appearance opts out: its raised surface already signals selection, so adding an icon there would be redundant. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: bf9277b 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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A selected
ToggleButtoncurrently reads only from its border and fill. This adds an explicit selection affordance, matching the Figma work in the LaunchPad branch.Two new props on
ToggleButton:icon— leading icon shown while the button is not selected.selectedIcon— leading icon shown while it is selected. Defaults tocheck-circle; passnullto opt out.The two never render together: selecting a button with a leading
iconswaps that icon forcheck-circlerather than stacking them, so a button shows exactly one icon in either state.appearance="elevated"defaultsselectedIcontonulland shows no icon when selected — its raised surface already makes the selection legible, so a check would be redundant. PassingselectedIconexplicitly still opts back in.Implementation wraps children in
composeRenderPropsto read RAC'sisSelectedrender prop, so no new state and no change to the existing class/variant logic. The icon isaria-hidden; selection is still announced througharia-pressed/aria-selected.Reviewer call-out
This changes rendered output for every existing selected default-appearance toggle button, not just new usages — in gonfalon that includes the access-token status filter and
CategoryPills. Two things worth an explicit decision:minor(additive props, additive behavior), but the repo's rules list "changed default" undermajor. Happy to re-cut asmajorif you read it that way.5% / 10% / 50% / 90% / Custom. The design decision so far was to accept this rather than reserve icon space; say the word if you'd prefer it reserved.Screenshots
Selected state — a selected button that has no icon of its own now shows
check-circle. This is the existingToggleButtonGroup→Examplestory, unchanged apart from the new default:Group where every button has an icon — "First" is selected, so its
flaskhas been replaced by the check, while "Second" and "Third" keepflagandtoggle-on. One icon per button in either state, never two:Chromatic has the full picture: 14 visual and accessibility changes to accept as baselines, covering every existing story with a selected toggle.
Testing approaches
ToggleButton.spec.tsxcovering: check renders when selected, no icon when unselected, leading icon while unselected, icon-swaps-to-check on selection, customselectedIcon,selectedIcon={null}, elevated renders nothing, and the icon isaria-hidden.ToggleButtonGroup.stories.tsx—SelectedIconSwap(with aplayfunction that clicks through to show the swap) andWithoutSelectedIcon.pnpm typecheck,pnpm oxlint:js,pnpm fmt:checkclean; all 16 tests across the three toggle specs pass.Screenshots are hosted on the
assets/pr-2017-screenshotsbranch (images only, never merged) — safe to delete once this lands.