shadcn.io is not affiliated with official shadcn/ui
Button Group examples · Display
Chart Controls Button Group for React
A chart type picker with Line, Bar and Pie, as labeled buttons and as icon-only buttons that share one selection.
The switch above a dashboard chart. Line, Bar and Pie sit in one group; the selected type gets the solid default fill and aria-pressed, the others stay outline. The icon-only row reads the same state, so picking Bar in either row lights up both.
Preview
Installation
FAQ
How is the active chart type tracked?
One value, starting at line. Each button carries its type as its value, and one handler stores the value of the button you press. A button whose type matches gets variant="default", the rest outline.
Why do both rows change together?
They read the same value. The rows are two layouts of one control, labeled and icon-only.
How are the icon-only buttons named?
Each has an aria-label, Line, Bar or Pie, and size="icon-sm". The icons have aria-hidden="true".
How does a screen reader know which type is on?
Each button sets aria-pressed to whether it's the selected type, so the active one is announced as pressed.
Should this be a Toggle Group?
It can be. A Toggle Group with a single value handles the selection and Arrow key movement for you. This demo uses plain buttons, so Tab moves between them.
Related
- Map Controls Button GroupA map layer picker with Satellite, Road
- Timeline Controls Button GroupA time range picker with Day, Week, Month
- View Switcher Button GroupA view switcher for Grid, List and Cards
- Default Toggle GroupA toggle group for bold, italic and
- A line chartA line chart drawing one series as a
- A bar chartA bar chart with rounded corners