2020-08-06 13:07:24 +00:00
# Button Group
[component-header:sl-button-group]
Button groups can be used to group related buttons into sections.
```html preview
< sl-button-group >
< sl-button > Left< / sl-button >
< sl-button > Center< / sl-button >
< sl-button > Right< / sl-button >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlButton, SlButtonGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< SlButtonGroup >
< SlButton > Left< / SlButton >
< SlButton > Center< / SlButton >
< SlButton > Right< / SlButton >
< / SlButtonGroup >
);
```
2020-08-06 13:07:24 +00:00
## Examples
### Button Sizes
All button sizes are supported, but avoid mixing sizes within the same button group.
```html preview
< sl-button-group >
< sl-button size = "small" > Left< / sl-button >
< sl-button size = "small" > Center< / sl-button >
< sl-button size = "small" > Right< / sl-button >
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
< sl-button-group >
< sl-button size = "medium" > Left< / sl-button >
< sl-button size = "medium" > Center< / sl-button >
< sl-button size = "medium" > Right< / sl-button >
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
< sl-button-group >
< sl-button size = "large" > Left< / sl-button >
< sl-button size = "large" > Center< / sl-button >
< sl-button size = "large" > Right< / sl-button >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlButton, SlButtonGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlButtonGroup >
< SlButton size = "small" > Left< / SlButton >
< SlButton size = "small" > Center< / SlButton >
< SlButton size = "small" > Right< / SlButton >
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
< SlButton size = "medium" > Left< / SlButton >
< SlButton size = "medium" > Center< / SlButton >
< SlButton size = "medium" > Right< / SlButton >
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
< SlButton size = "large" > Left< / SlButton >
< SlButton size = "large" > Center< / SlButton >
< SlButton size = "large" > Right< / SlButton >
< / SlButtonGroup >
< />
);
```
2020-08-06 13:07:24 +00:00
### Theme Buttons
2020-12-23 13:48:48 +00:00
Theme buttons are supported through the button's `type` attribute.
2020-08-06 13:07:24 +00:00
```html preview
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "primary" > Left< / sl-button >
< sl-button variant = "primary" > Center< / sl-button >
< sl-button variant = "primary" > Right< / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
2020-12-23 13:48:48 +00:00
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "success" > Left< / sl-button >
< sl-button variant = "success" > Center< / sl-button >
< sl-button variant = "success" > Right< / sl-button >
2020-12-23 13:48:48 +00:00
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-12-23 13:48:48 +00:00
2020-08-06 13:07:24 +00:00
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "neutral" > Left< / sl-button >
< sl-button variant = "neutral" > Center< / sl-button >
< sl-button variant = "neutral" > Right< / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "warning" > Left< / sl-button >
< sl-button variant = "warning" > Center< / sl-button >
< sl-button variant = "warning" > Right< / sl-button >
2020-12-23 13:48:48 +00:00
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-12-23 13:48:48 +00:00
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "danger" > Left< / sl-button >
< sl-button variant = "danger" > Center< / sl-button >
< sl-button variant = "danger" > Right< / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlButton, SlButtonGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "primary" > Left< / SlButton >
< SlButton variant = "primary" > Center< / SlButton >
< SlButton variant = "primary" > Right< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "success" > Left< / SlButton >
< SlButton variant = "success" > Center< / SlButton >
< SlButton variant = "success" > Right< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "neutral" > Left< / SlButton >
< SlButton variant = "neutral" > Center< / SlButton >
< SlButton variant = "neutral" > Right< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "warning" > Left< / SlButton >
< SlButton variant = "warning" > Center< / SlButton >
< SlButton variant = "warning" > Right< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "danger" > Left< / SlButton >
< SlButton variant = "danger" > Center< / SlButton >
< SlButton variant = "danger" > Right< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
< />
);
```
2020-08-06 13:07:24 +00:00
### Pill Buttons
Pill buttons are supported through the button's `pill` attribute.
```html preview
< sl-button-group >
< sl-button size = "small" pill > Left< / sl-button >
< sl-button size = "small" pill > Center< / sl-button >
< sl-button size = "small" pill > Right< / sl-button >
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
< sl-button-group >
< sl-button size = "medium" pill > Left< / sl-button >
< sl-button size = "medium" pill > Center< / sl-button >
< sl-button size = "medium" pill > Right< / sl-button >
< / sl-button-group >
2022-03-02 15:10:41 +00:00
< br / > < br / >
2020-08-06 13:07:24 +00:00
< sl-button-group >
< sl-button size = "large" pill > Left< / sl-button >
< sl-button size = "large" pill > Center< / sl-button >
< sl-button size = "large" pill > Right< / sl-button >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlButton, SlButtonGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlButtonGroup >
2022-03-02 15:10:41 +00:00
< SlButton size = "small" pill >
Left
< / SlButton >
< SlButton size = "small" pill >
Center
< / SlButton >
< SlButton size = "small" pill >
Right
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2022-03-02 15:10:41 +00:00
< SlButton size = "medium" pill >
Left
< / SlButton >
< SlButton size = "medium" pill >
Center
< / SlButton >
< SlButton size = "medium" pill >
Right
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
2022-03-02 15:10:41 +00:00
< br / >
< br / >
2021-11-04 22:12:47 +00:00
< SlButtonGroup >
2022-03-02 15:10:41 +00:00
< SlButton size = "large" pill >
Left
< / SlButton >
< SlButton size = "large" pill >
Center
< / SlButton >
< SlButton size = "large" pill >
Right
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlButtonGroup >
< />
);
```
2020-08-06 13:07:24 +00:00
### Dropdowns in Button Groups
2021-09-19 15:43:16 +00:00
Dropdowns can be placed inside button groups as long as the trigger is an `<sl-button>` element.
2020-08-06 13:07:24 +00:00
```html preview
2022-03-02 15:10:41 +00:00
< sl-button-group >
2020-08-06 13:07:24 +00:00
< sl-button > Button< / sl-button >
< sl-button > Button< / sl-button >
< sl-dropdown >
< sl-button slot = "trigger" caret > Dropdown< / sl-button >
< sl-menu >
< sl-menu-item > Item 1< / sl-menu-item >
< sl-menu-item > Item 2< / sl-menu-item >
< sl-menu-item > Item 3< / sl-menu-item >
< / sl-menu >
< / sl-dropdown >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlButtonGroup, SlDropdown, SlMenu, SlMenuItem } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const App = () => (
2022-03-02 15:10:41 +00:00
< SlButtonGroup >
2021-11-04 22:12:47 +00:00
< SlButton > Button< / SlButton >
< SlButton > Button< / SlButton >
< SlDropdown >
2022-03-02 15:10:41 +00:00
< SlButton slot = "trigger" caret >
Dropdown
< / SlButton >
2021-11-04 22:12:47 +00:00
< SlMenu >
< SlMenuItem > Item 1< / SlMenuItem >
< SlMenuItem > Item 2< / SlMenuItem >
< SlMenuItem > Item 3< / SlMenuItem >
< / SlMenu >
< / SlDropdown >
< / SlButtonGroup >
);
```
2020-12-23 13:48:48 +00:00
### Split Buttons
2022-03-16 21:44:40 +00:00
Create a split button using a button and a dropdown. Use a [visually hidden ](/components/visually-hidden ) label to ensure the dropdown is accessible to users with assistive devices.
2020-12-23 13:48:48 +00:00
```html preview
2022-03-02 15:10:41 +00:00
< sl-button-group >
2021-12-13 22:38:40 +00:00
< sl-button variant = "primary" > Save< / sl-button >
2020-12-23 13:48:48 +00:00
< sl-dropdown placement = "bottom-end" >
2022-03-16 21:44:40 +00:00
< sl-button slot = "trigger" variant = "primary" caret >
< sl-visually-hidden > More options< / sl-visually-hidden >
< / sl-button >
2020-12-23 13:48:48 +00:00
< sl-menu >
< sl-menu-item > Save< / sl-menu-item >
< sl-menu-item > Save as… < / sl-menu-item >
< sl-menu-item > Save all< / sl-menu-item >
< / sl-menu >
< / sl-dropdown >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlButtonGroup, SlDropdown, SlMenu, SlMenuItem } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const App = () => (
2022-03-02 15:10:41 +00:00
< SlButtonGroup >
2021-12-13 22:38:40 +00:00
< SlButton variant = "primary" > Save< / SlButton >
2021-11-04 22:12:47 +00:00
< SlDropdown placement = "bottom-end" >
2021-12-13 22:38:40 +00:00
< SlButton slot = "trigger" variant = "primary" caret > < / SlButton >
2021-11-04 22:12:47 +00:00
< SlMenu >
< SlMenuItem > Save< / SlMenuItem >
< SlMenuItem > Save as… < / SlMenuItem >
< SlMenuItem > Save all< / SlMenuItem >
< / SlMenu >
< / SlDropdown >
< / SlButtonGroup >
);
```
2020-08-06 13:07:24 +00:00
### Tooltips in Button Groups
Buttons can be wrapped in tooltips to provide more detail when the user interacts with them.
```html preview
< sl-button-group >
< sl-tooltip content = "I'm on the left" >
< sl-button > Left< / sl-button >
< / sl-tooltip >
< sl-tooltip content = "I'm in the middle" >
< sl-button > Center< / sl-button >
< / sl-tooltip >
< sl-tooltip content = "I'm on the right" >
< sl-button > Right< / sl-button >
< / sl-tooltip >
< / sl-button-group >
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlButtonGroup, SlTooltip } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const App = () => (
< >
< SlButtonGroup >
< SlTooltip content = "I'm on the left" >
< SlButton > Left< / SlButton >
< / SlTooltip >
< SlTooltip content = "I'm in the middle" >
< SlButton > Center< / SlButton >
< / SlTooltip >
< SlTooltip content = "I'm on the right" >
< SlButton > Right< / SlButton >
< / SlTooltip >
< / SlButtonGroup >
< />
);
```
2020-08-06 13:07:24 +00:00
### Toolbar Example
Create interactive toolbars with button groups.
```html preview
< div class = "button-group-toolbar" >
< sl-button-group label = "History" >
< sl-tooltip content = "Undo" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "arrow-counterclockwise" label = "Undo" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< sl-tooltip content = "Redo" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "arrow-clockwise" label = "Redo" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< / sl-button-group >
< sl-button-group label = "Formatting" >
< sl-tooltip content = "Bold" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "type-bold" label = "Bold" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< sl-tooltip content = "Italic" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "type-italic" label = "Italic" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< sl-tooltip content = "Underline" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "type-underline" label = "Underline" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< / sl-button-group >
< sl-button-group label = "Alignment" >
< sl-tooltip content = "Align Left" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "justify-left" label = "Align Left" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< sl-tooltip content = "Align Center" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "justify" label = "Align Center" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< sl-tooltip content = "Align Right" >
2022-03-16 21:44:40 +00:00
< sl-button > < sl-icon name = "justify-right" label = "Align Right" > < / sl-icon > < / sl-button >
2020-08-06 13:07:24 +00:00
< / sl-tooltip >
< / sl-button-group >
< / div >
< style >
.button-group-toolbar sl-button-group:not(:last-of-type) {
2020-09-14 21:07:09 +00:00
margin-right: var(--sl-spacing-x-small);
2020-08-06 13:07:24 +00:00
}
< / style >
```
2021-11-04 22:12:47 +00:00
```jsx react
2022-03-02 15:10:41 +00:00
import { SlButton, SlButtonGroup, SlIcon, SlTooltip } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
const css = `
.button-group-toolbar sl-button-group:not(:last-of-type) {
margin-right: var(--sl-spacing-x-small);
}
`;
const App = () => (
< >
2021-11-05 14:06:06 +00:00
< div className = "button-group-toolbar" >
2021-11-04 22:12:47 +00:00
< SlButtonGroup label = "History" >
< SlTooltip content = "Undo" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "arrow-counterclockwise" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< SlTooltip content = "Redo" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "arrow-clockwise" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< / SlButtonGroup >
< SlButtonGroup label = "Formatting" >
< SlTooltip content = "Bold" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "type-bold" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< SlTooltip content = "Italic" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "type-italic" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< SlTooltip content = "Underline" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "type-underline" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< / SlButtonGroup >
< SlButtonGroup label = "Alignment" >
< SlTooltip content = "Align Left" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "justify-left" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< SlTooltip content = "Align Center" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "justify" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< SlTooltip content = "Align Right" >
2022-03-02 15:10:41 +00:00
< SlButton >
< SlIcon name = "justify-right" > < / SlIcon >
< / SlButton >
2021-11-04 22:12:47 +00:00
< / SlTooltip >
< / SlButtonGroup >
< / div >
< style > { c s s } < / style >
< />
);
```
2020-08-06 13:07:24 +00:00
[component-metadata:sl-button-group]