Repository navigation
[Feature] ToggleGroup: match shadcn (Base UI + vega) #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d57627
[Feature] ToggleGroup: match shadcn (Base UI + vega)
cirdes 8b0bddf
ToggleGroup: keep a tab stop when items change; no scroll at the ends
cirdes 5b7bed9
Merge remote-tracking branch 'origin/main' into audit-toggle-group
cirdes 7c84e1a
ToggleGroup: one tab stop in the server HTML; validate loop_focus
cirdes fac5fc0
Merge remote-tracking branch 'origin/main' into audit-toggle-group
cirdes be39304
Toggle: drop the data-[state=on]:bg-muted compat class
cirdes 97f9852
Merge remote-tracking branch 'origin/main' into audit-toggle-group
cirdes bc00f7c
ToggleGroup: name the Stimulus values test for what it checks
cirdes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| shadcn: toggle-group | ||
| shadcn_sha: 8a3536678a528cc012b9e62484290e79d0be410f | ||
| kind: form_control | ||
| docs_view: toggle_group | ||
| parts: | ||
| ToggleGroup: toggle-group | ||
| ToggleGroupItem: toggle-group-item | ||
| selectors: | ||
| ToggleGroup: '[data-slot="toggle-group"]' | ||
| ToggleGroupItem: '[data-slot="toggle-group-item"]' | ||
| props: | ||
| # shadcn's own props (variant, size, spacing, orientation) + Base UI ToggleGroup.Props. | ||
| ToggleGroup: | ||
| variant: variant | ||
| size: size | ||
| spacing: spacing | ||
| orientation: orientation | ||
| multiple: type | ||
| # Base UI defaultValue is always an array; RubyUI value is a scalar for type: :single | ||
| # and an array for :multiple. | ||
| defaultValue: value | ||
| value: null | ||
| onValueChange: null | ||
| disabled: disabled | ||
| loopFocus: loop_focus | ||
| # shadcn's variant/size + Base UI Toggle.Props. | ||
| ToggleGroupItem: | ||
| variant: variant | ||
| size: size | ||
| value: value | ||
| disabled: disabled # item kwarg reaches Toggle and overrides the group value | ||
| pressed: null | ||
| defaultPressed: null | ||
| onPressedChange: null | ||
| rubyui_only: | ||
| ToggleGroup: [name] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| - component: toggle_group | ||
| dimension: Behavior | ||
| rubyui: "With a selection, Tab enters the group on the first pressed item" | ||
| shadcn: "Base UI makes the first item the tab stop whatever is pressed" | ||
| reason: "Landing on the current choice tells keyboard users the group's value at once and saves arrow presses; with no selection both enter on the first item." | ||
| since: "2026-11-04" | ||
| - component: toggle_group | ||
| dimension: Props | ||
| rubyui: "value sets the initial state; the state reaches forms through hidden inputs (name)" | ||
| shadcn: "value/onValueChange, and pressed/defaultPressed/onPressedChange on items (controlled React state)" | ||
| reason: "Server-rendered Phlex has no controlled state or JS callbacks; listen to clicks on the items or read the hidden inputs." | ||
| since: "2026-11-04" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Four groups, same strings and options on both sides: | ||
| # - Alignment: single, outline, spacing 0 (joined), nothing pressed. data-audit-trigger | ||
| # sits on Left: with no selection both libraries make the first item the tab stop | ||
| # (with a selection RubyUI picks the pressed item, Base UI the first one). | ||
| # - Formatting: multiple, default variant, spacing 1, Bold pressed. | ||
| # - Size: single, vertical, outline, size sm, spacing 0, Medium pressed. | ||
| # - Range: multiple, outline, spacing 2, whole group disabled. | ||
| groups: [Alignment, Formatting, Size, Range] | ||
| alignment: [Left, Center, Right] | ||
| formatting: [Bold, Italic, Underline] | ||
| size: [Small, Medium, Large] | ||
| range: [Day, Week] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ShadcnAuditFixtures | ||
| # RubyUI side of audit/fixtures/toggle_group (strings in content.yml). | ||
| class ToggleGroup < Phlex::HTML | ||
| include RubyUI | ||
|
|
||
| def view_template | ||
| div(id: "toggle-group-fixture", class: "flex flex-col items-start gap-6") do | ||
| ToggleGroup(type: :single, name: "alignment", variant: :outline, spacing: 0, aria: {label: "Alignment"}) do |g| | ||
| g.ToggleGroupItem(value: "left", data: {audit_trigger: true}) { "Left" } | ||
| g.ToggleGroupItem(value: "center") { "Center" } | ||
| g.ToggleGroupItem(value: "right") { "Right" } | ||
| end | ||
| ToggleGroup(type: :multiple, name: "formatting", value: %w[bold], spacing: 1, aria: {label: "Formatting"}) do |g| | ||
| g.ToggleGroupItem(value: "bold") { "Bold" } | ||
| g.ToggleGroupItem(value: "italic") { "Italic" } | ||
| g.ToggleGroupItem(value: "underline") { "Underline" } | ||
| end | ||
| ToggleGroup(type: :single, name: "size", value: "medium", variant: :outline, size: :sm, spacing: 0, orientation: :vertical, aria: {label: "Size"}) do |g| | ||
| g.ToggleGroupItem(value: "small") { "Small" } | ||
| g.ToggleGroupItem(value: "medium") { "Medium" } | ||
| g.ToggleGroupItem(value: "large") { "Large" } | ||
| end | ||
| ToggleGroup(type: :multiple, name: "range", variant: :outline, spacing: 2, disabled: true, aria: {label: "Range"}) do |g| | ||
| g.ToggleGroupItem(value: "day") { "Day" } | ||
| g.ToggleGroupItem(value: "week") { "Week" } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group" | ||
|
|
||
| export default function ToggleGroupFixture() { | ||
| return ( | ||
| <div id="toggle-group-fixture" className="flex flex-col items-start gap-6"> | ||
| <ToggleGroup aria-label="Alignment" variant="outline" spacing={0}> | ||
| <ToggleGroupItem value="left" data-audit-trigger="">Left</ToggleGroupItem> | ||
| <ToggleGroupItem value="center">Center</ToggleGroupItem> | ||
| <ToggleGroupItem value="right">Right</ToggleGroupItem> | ||
| </ToggleGroup> | ||
| <ToggleGroup aria-label="Formatting" multiple spacing={1} defaultValue={["bold"]}> | ||
| <ToggleGroupItem value="bold">Bold</ToggleGroupItem> | ||
| <ToggleGroupItem value="italic">Italic</ToggleGroupItem> | ||
| <ToggleGroupItem value="underline">Underline</ToggleGroupItem> | ||
| </ToggleGroup> | ||
| <ToggleGroup aria-label="Size" variant="outline" size="sm" spacing={0} orientation="vertical" defaultValue={["medium"]}> | ||
| <ToggleGroupItem value="small">Small</ToggleGroupItem> | ||
| <ToggleGroupItem value="medium">Medium</ToggleGroupItem> | ||
| <ToggleGroupItem value="large">Large</ToggleGroupItem> | ||
| </ToggleGroup> | ||
| <ToggleGroup aria-label="Range" multiple variant="outline" spacing={2} disabled> | ||
| <ToggleGroupItem value="day">Day</ToggleGroupItem> | ||
| <ToggleGroupItem value="week">Week</ToggleGroupItem> | ||
| </ToggleGroup> | ||
| </div> | ||
| ) | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.