- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Typography
Installation#
pnpm dlx shadcn@latest add @force-ui-svelte/button-group
Usage#
<script lang="ts">
import * as ButtonGroup from "$lib/components/ui/button-group/index.js";
</script><ButtonGroup.Root>
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup.Root>Composition#
Use the following composition to build a ButtonGroup:
ButtonGroup.Root
├── Button or Input
├── ButtonGroup.Separator
└── ButtonGroup.TextAccessibility#
- The
ButtonGroupcomponent has theroleattribute set togroup. - Use
Tabto navigate between the buttons in the group. - Use
aria-labeloraria-labelledbyto label the button group.
<ButtonGroup.Root aria-label="Button group">
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup.Root>ButtonGroup vs ToggleGroup#
- Use the
ButtonGroupcomponent when you want to group buttons that perform an action. - Use the
ToggleGroupcomponent when you want to group buttons that toggle a state.
Examples#
Orientation#
Set the orientation prop to change the button group layout.
Size#
Control the size of buttons using the size prop on individual buttons.
Nested#
Nest <ButtonGroup.Root> components to create button groups with spacing.
Separator#
The ButtonGroup.Separator component visually divides buttons within a group.
Buttons with variant outline do not need a separator since they have a border. For other variants, a separator is recommended to improve the visual hierarchy.
Split#
Create a split button group by adding two buttons separated by a ButtonGroup.Separator.
Input#
Wrap an Input component with buttons.
Input Group#
Wrap an InputGroup component to create complex input layouts.
Dropdown Menu#
Create a split button group with a DropdownMenu component.
Select#
Pair with a Select component.
Popover#
Use with a Popover component.
RTL#
To enable RTL support in Force UI, see the RTL configuration guide.
API Reference#
ButtonGroup.Root#
The ButtonGroup.Root component is a container that groups related buttons together with consistent styling.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "horizontal" |
<ButtonGroup.Root>
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup.Root>Nest multiple button groups to create complex layouts with spacing. See the nested example for more details.
<ButtonGroup.Root>
<ButtonGroup.Root />
<ButtonGroup.Root />
</ButtonGroup.Root>ButtonGroup.Separator#
The ButtonGroup.Separator component visually divides buttons within a group.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "vertical" |
<ButtonGroup.Root>
<Button>Button 1</Button>
<ButtonGroup.Separator />
<Button>Button 2</Button>
</ButtonGroup.Root>ButtonGroup.Text#
Use this component to display text within a button group.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
<ButtonGroup.Root>
<ButtonGroup.Text>Text</ButtonGroup.Text>
<Button>Button</Button>
</ButtonGroup.Root>