Skip to content

feat: segmented-control component - #4867

Open
pdanpdan wants to merge 3 commits into
saadeghi:masterfrom
pdanpdan:feat/segmented-control
Open

pdanpdan wants to merge 3 commits into
saadeghi:masterfrom
pdanpdan:feat/segmented-control

Conversation

@pdanpdan

@pdanpdan pdanpdan commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
  • segments are native radios: a label wrapping the input, or an input with aria-label, so the group name and arrow keys work without JS
  • the track is base-200 like tabs-box and the selected segment is a base-100 chip with a 1px base-content/20 border and the depth shadow; the border is reserved on every segment, so selecting one does not move the other labels
  • radius stay concentric: track = radius-field + padding, chip = radius-field, so pill themes get a pill chip and 0-radius themes stay square
  • optional segmented-control-indicator anchors to the checked radio with CSS anchor positioning, so the selection slides between segments with transition (from megamenu); without anchor positioning the indicator is not rendered and the checked segment paints its own chip
  • color classes (primary, secondary, accent, neutral, success, warning, info, error) paint the chip and the indicator with that color and switch the label to the matching content color
  • sizes xs..xl follow the field size scale
  • forced-colors marks the selected segment with a 1px frame and leaves the palette to the browser; the focus ring is not overridden by that frame

example:
v1: https://play.tailwindcss.com/RKdNbjFQ4r
v2: https://play.tailwindcss.com/S2w2xgrqhp - accept checkboxes (disables animation if mixed - but can be composed)
v3: https://play.tailwindcss.com/EoeuMXy5l6 - improved examples (and small fixes)
v4: https://play.tailwindcss.com/f892BIOdLK - add dividers and joined mode

@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

@saadeghi

Copy link
Copy Markdown
Owner

This is great.

The only concern I have:
There's a overlap with tab, and I would say it's a big overlap since daisyUI tab can be radio inputs as well.
I am positive about adding this as a new component but before making that decision, we have to be clear to the developers about the differences, when/where to use tab and when/where to use segmented control.

@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

@pdanpdan

Copy link
Copy Markdown
Contributor Author

I would say this can act as a toolbar / controls bar.
I agree that it is similar to tabs-box, but tabs somehow have the semantics of selecting the content associated with them.
This one is designed more to change options - potayto, potahto

@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

@pdanpdan
pdanpdan force-pushed the feat/segmented-control branch from 80faaaf to 76e4e80 Compare November 17, 2026 12:05
@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

- segments are native radios: a label wrapping the input, or an input with aria-label, so the group name and arrow keys work without JS
- the track is base-200 like tabs-box and the selected segment is a base-100 chip with a 1px base-content/20 border and the depth shadow; the border is reserved on every segment, so selecting one does not move the other labels
- radius stay concentric: track = radius-field + padding, chip = radius-field, so pill themes get a pill chip and 0-radius themes stay square
- optional `segmented-control-indicator` anchors to the checked radio with CSS anchor positioning, so the selection slides between segments with transition (from megamenu); without anchor positioning the indicator is not rendered and the checked segment paints its own chip
- color classes (primary, secondary, accent, neutral, success, warning, info, error) paint the chip and the indicator with that color and switch the label to the matching content color
- sizes xs..xl follow the field size scale
- forced-colors marks the selected segment with a 1px frame and leaves the palette to the browser; the focus ring is not overridden by that frame

example: https://play.tailwindcss.com/kr6ptonJwP
@pdanpdan
pdanpdan force-pushed the feat/segmented-control branch from 76e4e80 to b1020f1 Compare November 17, 2026 12:20
@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

- `.segmented-control-delimited` / `.segmented-control-item-delimited` draw separators between segments
- `.segmented-control-joined` removes gaps so segments touch with only the outer corners rounded
- items and the indicator now inherit the control's radius
- nested controls use a transparent track so the indicator moving stays visible

example: https://play.tailwindcss.com/f892BIOdLK
@github-actions

Copy link
Copy Markdown

1 component changed. Basic playground: Before vs. After.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants