[v3] Animated selection indicator for ToggleButtonGroup (reuse the Tabs.Indicator pattern) #6742
Saidheerajgollu
started this conversation in
Feature requests
Replies: 1 comment
|
Opened #6743 with the implementation, rebased onto |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Tabsalready renders an animated pill that slides to the selected tab, using React Aria's newSelectionIndicator.ToggleButtonGroup— the segmented control, which is visually the same pattern — still hard-swaps a background colour on the selected button.I'd like to propose an opt-in
ToggleButtonGroup.Indicatorthat mirrorsTabs.Indicator, so both selection patterns in the library animate the same way. Following CONTRIBUTING I'm raising this before opening a PR, but I've built and verified it already so the proposal is concrete rather than hypothetical.Why this is a small change
React Aria's
ToggleButtonalready providesSelectionIndicatorContext:So an indicator placed inside a
ToggleButtonpicks up selection state with no extra wiring — the same wayTabs.Indicatorworks today. RAC provides this context inGridList,ListBox,Menu,RadioGroup,Table,Tabs,TagGroup,ToggleButtonandTree;Tabsis currently the only place HeroUI takes advantage of it.Proposed API
Identical in shape to
Tabs.Indicator— placed inside each button:Implementation
Branch: https://github.com/Saidheerajgollu/heroui/tree/feat/toggle-button-group-indicator (4 source files, +78 lines)
indicator: "toggle-button-group__indicator"slot added totoggleButtonGroupVariantsToggleButtonGroupIndicatorwrappingSelectionIndicator— the same 15-line shape asTabIndicator--toggle-button-bg-selectedtoken so the current visual identity is preserved, and copies the transition recipe from.tabs__indicator(translate, width, height, 250ms,var(--ease-out-fluid), with themotion-reduceoverride after the transition as the comment intabs.cssrequires)WithIndicatorStorybook storyBackwards compatible. The indicator is opt-in, and the static selected background is only neutralised for buttons that actually contain one:
Groups that don't use the indicator render byte-identically.
:has()is already used acrosspackages/styles/components.Verified:
pnpm build,pnpm lint,pnpm typecheckandprettier --checkall pass. SSR render confirms only the selected button emits the indicator element, unselected buttons emit nothing.Open questions for maintainers
ToggleButtonGroup.IndicatormirrorsTabs.Indicator. Would you prefer it on the button (ToggleButton.Indicator) since that's where it's rendered?RadioGroup/ListBox(e.g. segmented radio cards), or keep this toToggleButtonGroupfor now?Happy to open the PR, adjust the API, or drop it if this isn't a direction you want.
All reactions