shadcn.io is not affiliated with official shadcn/ui
Button Group examples · Interactive
View Switcher Button Group for React
A view switcher for Grid, List and Cards layouts, as labeled buttons and as icon-only buttons that share one selection.
The layout switch at the top of a file browser or a product grid. Grid, List and Cards are labeled in the first row and icon-only in the second; both read one value, so the chosen layout is filled in each row and announced as pressed.
Preview
Installation
FAQ
How is the view tracked?
One value, starting at grid. Each button carries its own value, and pressing it stores that value. The matching button gets variant="default".
Why do both rows change together?
They read the same value. Show the labeled row where there's room and the icon row in a toolbar.
How are the icon-only buttons named?
Each has an aria-label, Grid, List or Cards, and size="icon-sm". The icons have aria-hidden="true".
How is the active view announced?
Its button sets aria-pressed, so a screen reader reads it as pressed.
Related
- Chart Controls Button GroupA chart type picker with Line, Bar and
- Segmented Control Button GroupTwo segmented controls of ghost buttons
- Density Controls Button GroupA display density picker with Compact
- Default Toggle GroupA toggle group for bold, italic and
- Standard CardA basic card with a title, a description
- Filter Chips Button GroupFilter buttons in two groups where