Group a series of buttons together on a single line with the button group.
Wrap a series of <Button />
s in a <ButtonGroup />
.
<ButtonGroup> <Button>Left</Button> <Button>Middle</Button> <Button>Right</Button> </ButtonGroup>;
Combine sets of <ButtonGroup />
s into a <ButtonToolbar />
for more complex components.
<ButtonToolbar> <ButtonGroup> <Button>1</Button> <Button>2</Button> <Button>3</Button> <Button>4</Button> </ButtonGroup> <ButtonGroup> <Button>5</Button> <Button>6</Button> <Button>7</Button> </ButtonGroup> <ButtonGroup> <Button>8</Button> </ButtonGroup> </ButtonToolbar>;
Instead of applying button sizing props to every button in a group, just add bsSize
prop to the <ButtonGroup />
.
<div> <ButtonToolbar> <ButtonGroup bsSize="large"> <Button>Left</Button> <Button>Middle</Button> <Button>Right</Button> </ButtonGroup> </ButtonToolbar> <ButtonToolbar> <ButtonGroup> <Button>Left</Button> <Button>Middle</Button> <Button>Right</Button> </ButtonGroup> </ButtonToolbar> <ButtonToolbar> <ButtonGroup bsSize="small"> <Button>Left</Button> <Button>Middle</Button> <Button>Right</Button> </ButtonGroup> </ButtonToolbar> <ButtonToolbar> <ButtonGroup bsSize="xsmall"> <Button>Left</Button> <Button>Middle</Button> <Button>Right</Button> </ButtonGroup> </ButtonToolbar> </div>;
You can place other button types within the <ButtonGroup />
like <DropdownButton />
s.
<ButtonGroup> <Button>1</Button> <Button>2</Button> <DropdownButton title="Dropdown" id="bg-nested-dropdown"> <MenuItem eventKey="1">Dropdown link</MenuItem> <MenuItem eventKey="2">Dropdown link</MenuItem> </DropdownButton> </ButtonGroup>;
Make a set of buttons appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.
Just add vertical
to the <ButtonGroup />
.
<ButtonGroup vertical> <Button>Button</Button> <Button>Button</Button> <DropdownButton title="Dropdown" id="bg-vertical-dropdown-1"> <MenuItem eventKey="1">Dropdown link</MenuItem> <MenuItem eventKey="2">Dropdown link</MenuItem> </DropdownButton> <Button>Button</Button> <Button>Button</Button> <DropdownButton title="Dropdown" id="bg-vertical-dropdown-2"> <MenuItem eventKey="1">Dropdown link</MenuItem> <MenuItem eventKey="2">Dropdown link</MenuItem> </DropdownButton> <DropdownButton title="Dropdown" id="bg-vertical-dropdown-3"> <MenuItem eventKey="1">Dropdown link</MenuItem> <MenuItem eventKey="2">Dropdown link</MenuItem> </DropdownButton> </ButtonGroup>;
Moreover, you can have buttons be block level elements so they take the full width of their container, just add block
to the <ButtonGroup />
, in addition to the vertical
you just added.
<ButtonGroup vertical block> <Button>Full width button</Button> <Button>Full width button</Button> </ButtonGroup>;
Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with button dropdowns within the button group.
There are some issues and workarounds required when using this property, please see bootstrap’s button group docs for more specifics.
Just add justified
to the <ButtonGroup />
.
<ButtonGroup justified> <Button href="#">Left</Button> <Button href="#">Middle</Button> <DropdownButton title="Dropdown" id="bg-justified-dropdown"> <MenuItem eventKey="1">Dropdown link</MenuItem> <MenuItem eventKey="2">Dropdown link</MenuItem> </DropdownButton> </ButtonGroup>;
For checkboxes or radio buttons styled as Bootstrap buttons, use the<ToggleButtonGroup>
and <ToggleButton>
components. The group behaves as a form component, where the value is an array of the selected eventKey
s for checkbox groups or the selected eventKey
for radio groups.
There is a known issue when including Bootstrap JS while using Toggle Button Groups. Therefore it is advised not use Bootstrap JS in conjunction with <ToggleButtonGroup>
and <ToggleButton>
.
<div> <ButtonToolbar> <ToggleButtonGroup type="checkbox" defaultValue={[1, 3]}> <ToggleButton value={1}>Checkbox 1 (pre-checked)</ToggleButton> <ToggleButton value={2}>Checkbox 2</ToggleButton> <ToggleButton value={3}>Checkbox 3 (pre-checked)</ToggleButton> </ToggleButtonGroup> </ButtonToolbar> <ButtonToolbar> <ToggleButtonGroup type="radio" name="options" defaultValue={1}> <ToggleButton value={1}>Radio 1 (pre-checked)</ToggleButton> <ToggleButton value={2}>Radio 2</ToggleButton> <ToggleButton value={3}>Radio 3</ToggleButton> </ToggleButtonGroup> </ButtonToolbar> </div>;
class ToggleButtonGroupControlled extends React.Component { constructor(props, context) { super(props, context); this.handleChange = this.handleChange.bind(this); this.state = { value: [1, 3] }; } handleChange(e) { this.setState({ value: e }); } render() { return ( <ToggleButtonGroup type="checkbox" value={this.state.value} onChange={this.handleChange} > <ToggleButton value={1}>Checkbox 1 (pre-checked)</ToggleButton> <ToggleButton value={2}>Checkbox 2</ToggleButton> <ToggleButton value={3}>Checkbox 3 (pre-checked)</ToggleButton> <ToggleButton value={4} disabled> Checkbox 4 (disabled) </ToggleButton> </ToggleButtonGroup> ); } } render(<ToggleButtonGroupControlled />);
Name | Type | Default | Description |
---|---|---|---|
vertical | boolean | false | |
justified | boolean | false | |
block | boolean | false | Display block buttons; only useful when used with the "vertical" prop. |
bsClass | string | 'btn-group' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
bsClass | string | 'btn-toolbar' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
name | string | An HTML Required if | |
value | any | controlled by: onChange , initial prop: defaultValue The value, or array of values, of the active (pressed) buttons | |
onChange | function | controls values Callback fired when a button is pressed, depending on whether the | |
type | one of: 'checkbox' , 'radio' | 'radio' | The input |
Name | Type | Default | Description |
---|---|---|---|
type | [type] | The | |
name | string | The HTML input name, used to group like checkboxes or radio buttons together semantically | |
checked | boolean | The checked state of the input, managed by ` | |
disabled | boolean | The disabled state of both the label and input | |
onChange | function | [onChange description] | |
value required | any | The value of the input, and unique identifier in the ToggleButtonGroup |