Bootstrap React Button group

Bootstrap React button group component allows to group a series of buttons and power them with JavaScript.

Basic example#

Wrap a series of <CButton> components in <CButtonGroup>.

1<CButtonGroup role="group" aria-label="Basic example">
2 <CButton color="primary">Left</CButton>
3 <CButton color="primary">Middle</CButton>
4 <CButton color="primary">Right</CButton>
5</CButtonGroup>
Ensure the correct role and provide a label#

For assistive technologies (ex. screen readers) to communicate that a series of buttons are grouped, a proper role attribute has to be provided. For button groups, this should be role="group", while toolbars should have a role="toolbar".

Besides, groups and toolbars should be provided an understandable label, as most assistive technologies will otherwise not declare them, despite the appearance of the specific role attribute. In the following examples provided here, we apply aria-label, but options such as aria-labelledby can also be used.

These classes can also be added to groups of links, as an alternative to the <CNav> components.

1<CButtonGroup>
2 <CButton href="#" color="primary" active>
3 Active link
4 </CButton>
5 <CButton href="#" color="primary">
6 Link
7 </CButton>
8 <CButton href="#" color="primary">
9 Link
10 </CButton>
11</CButtonGroup>

Mixed styles#

1<CButtonGroup role="group" aria-label="Basic mixed styles example">
2 <CButton color="danger">Left</CButton>
3 <CButton color="warning">Middle</CButton>
4 <CButton color="success">Right</CButton>
5</CButtonGroup>

Outlined styles#

1<CButtonGroup role="group" aria-label="Basic outlined example">
2 <CButton color="primary" variant="outline">
3 Left
4 </CButton>
5 <CButton color="primary" variant="outline">
6 Middle
7 </CButton>
8 <CButton color="primary" variant="outline">
9 Right
10 </CButton>
11</CButtonGroup>

Checkbox and radio button groups#

Combine button-like checkbox and radio toggle buttons into a seamless looking button group.

1<CButtonGroup role="group" aria-label="Basic checkbox toggle button group">
2 <CFormCheck
3 button={{ color: 'primary', variant: 'outline' }}
4 id="btncheck1"
5 autoComplete="off"
6 label="Checkbox 1"
7 />
8 <CFormCheck
9 button={{ color: 'primary', variant: 'outline' }}
10 id="btncheck2"
11 autoComplete="off"
12 label="Checkbox 2"
13 />
14 <CFormCheck
15 button={{ color: 'primary', variant: 'outline' }}
16 id="btncheck3"
17 autoComplete="off"
18 label="Checkbox 3"
19 />
20</CButtonGroup>
1<CButtonGroup role="group" aria-label="Basic checkbox toggle button group">
2 <CFormCheck
3 type="radio"
4 button={{ color: 'primary', variant: 'outline' }}
5 name="btnradio"
6 id="btnradio1"
7 autoComplete="off"
8 label="Radio 1"
9 />
10 <CFormCheck
11 type="radio"
12 button={{ color: 'primary', variant: 'outline' }}
13 name="btnradio"
14 id="btnradio2"
15 autoComplete="off"
16 label="Radio 2"
17 />
18 <CFormCheck
19 type="radio"
20 button={{ color: 'primary', variant: 'outline' }}
21 name="btnradio"
22 id="btnradio3"
23 autoComplete="off"
24 label="Radio 3"
25 />
26</CButtonGroup>

Button toolbar#

Join sets of button groups into button toolbars for more complicated components. Use utility classes as needed to space out groups, buttons, and more.

1<CButtonToolbar role="group" aria-label="Toolbar with button groups">
2 <CButtonGroup className="me-2" role="group" aria-label="First group">
3 <CButton color="primary">1</CButton>
4 <CButton color="primary">2</CButton>
5 <CButton color="primary">3</CButton>
6 <CButton color="primary">4</CButton>
7 </CButtonGroup>
8 <CButtonGroup className="me-2" role="group" aria-label="Second group">
9 <CButton color="secondary">5</CButton>
10 <CButton color="secondary">6</CButton>
11 <CButton color="secondary">7</CButton>
12 </CButtonGroup>
13 <CButtonGroup className="me-2" role="group" aria-label="Third group">
14 <CButton color="info">8</CButton>
15 </CButtonGroup>
16</CButtonToolbar>

Feel free to combine input groups with button groups in your toolbars. Similar to the example above, you’ll likely need some utilities through to space items correctly.

@
@
1<CButtonToolbar className="mb-3" role="group" aria-label="Toolbar with button groups">
2 <CButtonGroup className="me-2" role="group" aria-label="First group">
3 <CButton color="secondary" variant="outline">1</CButton>
4 <CButton color="secondary" variant="outline">2</CButton>
5 <CButton color="secondary" variant="outline">3</CButton>
6 <CButton color="secondary" variant="outline">4</CButton>
7 </CButtonGroup>
8 <CInputGroup>
9 <CInputGroupText>@</CInputGroupText>
10 <CFormInput placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon"/>
11 </CInputGroup>
12 </CButtonToolbar>
13 <CButtonToolbar className="justify-content-between" role="group" aria-label="Toolbar with button groups">
14 <CButtonGroup className="me-2" role="group" aria-label="First group">
15 <CButton color="secondary" variant="outline">1</CButton>
16 <CButton color="secondary" variant="outline">2</CButton>
17 <CButton color="secondary" variant="outline">3</CButton>
18 <CButton color="secondary" variant="outline">4</CButton>
19 </CButtonGroup>
20 <CInputGroup>
21 <CInputGroupText>@</CInputGroupText>
22 <CFormInput placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon"/>
23 </CInputGroup>
24 </CButtonToolbar>

Sizing#

Alternatively, of implementing button sizing classes to each button in a group, set size property to all <CButtonGroup>'s, including each one when nesting multiple groups.



1<CButtonGroup size="lg" role="group" aria-label="Large button group">
2 <CButton color="dark" variant="outline">Left</CButton>
3 <CButton color="dark" variant="outline">Middle</CButton>
4 <CButton color="dark" variant="outline">Right</CButton>
5 </CButtonGroup>
6 <br/>
7 <CButtonGroup role="group" aria-label="Default button group">
8 <CButton color="dark" variant="outline">Left</CButton>
9 <CButton color="dark" variant="outline">Middle</CButton>
10 <CButton color="dark" variant="outline">Right</CButton>
11 </CButtonGroup>
12 <br/>
13 <CButtonGroup size="sm" role="group" aria-label="Small button group">
14 <CButton color="dark" variant="outline">Left</CButton>
15 <CButton color="dark" variant="outline">Middle</CButton>
16 <CButton color="dark" variant="outline">Right</CButton>
17 </CButtonGroup>

Nesting#

Put a <CButtonGroup> inside another <CButtonGroup> when you need dropdown menus combined with a series of buttons.

1<CButtonGroup role="group" aria-label="Button group with nested dropdown">
2 <CButton color="primary">1</CButton>
3 <CButton color="primary">2</CButton>
4 <CDropdown variant="btn-group">
5 <CDropdownToggle color="primary">Dropdown</CDropdownToggle>
6 <CDropdownMenu>
7 <CDropdownItem href="#">Action</CDropdownItem>
8 <CDropdownItem href="#">Another action</CDropdownItem>
9 <CDropdownItem href="#">Something else here</CDropdownItem>
10 <CDropdownDivider />
11 <CDropdownItem href="#">Separated link</CDropdownItem>
12 </CDropdownMenu>
13 </CDropdown>
14</CButtonGroup>

Vertical variation#

Create a set of buttons that appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.

1<CButtonGroup vertical role="group" aria-label="Vertical button group">
2 <CButton color="dark">Button</CButton>
3 <CButton color="dark">Button</CButton>
4 <CButton color="dark">Button</CButton>
5 <CButton color="dark">Button</CButton>
6 <CButton color="dark">Button</CButton>
7 <CButton color="dark">Button</CButton>
8 <CButton color="dark">Button</CButton>
9</CButtonGroup>
1<CButtonGroup vertical role="group" aria-label="Vertical button group">
2 <CButton color="primary">Button</CButton>
3 <CButton color="primary">Button</CButton>
4 <CDropdown variant="btn-group">
5 <CDropdownToggle color="primary">Dropdown</CDropdownToggle>
6 <CDropdownMenu>
7 <CDropdownItem href="#">Action</CDropdownItem>
8 <CDropdownItem href="#">Another action</CDropdownItem>
9 <CDropdownItem href="#">Something else here</CDropdownItem>
10 <CDropdownDivider />
11 <CDropdownItem href="#">Separated link</CDropdownItem>
12 </CDropdownMenu>
13 </CDropdown>
14 <CButton color="primary">Button</CButton>
15 <CButton color="primary">Button</CButton>
16 <CDropdown variant="btn-group">
17 <CDropdownToggle color="primary">Dropdown</CDropdownToggle>
18 <CDropdownMenu>
19 <CDropdownItem href="#">Action</CDropdownItem>
20 <CDropdownItem href="#">Another action</CDropdownItem>
21 <CDropdownItem href="#">Something else here</CDropdownItem>
22 <CDropdownDivider />
23 <CDropdownItem href="#">Separated link</CDropdownItem>
24 </CDropdownMenu>
25 </CDropdown>
26 <CDropdown variant="btn-group">
27 <CDropdownToggle color="primary">Dropdown</CDropdownToggle>
28 <CDropdownMenu>
29 <CDropdownItem href="#">Action</CDropdownItem>
30 <CDropdownItem href="#">Another action</CDropdownItem>
31 <CDropdownItem href="#">Something else here</CDropdownItem>
32 <CDropdownDivider />
33 <CDropdownItem href="#">Separated link</CDropdownItem>
34 </CDropdownMenu>
35 </CDropdown>
36 <CDropdown variant="btn-group">
37 <CDropdownToggle color="primary">Dropdown</CDropdownToggle>
38 <CDropdownMenu>
39 <CDropdownItem href="#">Action</CDropdownItem>
40 <CDropdownItem href="#">Another action</CDropdownItem>
41 <CDropdownItem href="#">Something else here</CDropdownItem>
42 <CDropdownDivider />
43 <CDropdownItem href="#">Separated link</CDropdownItem>
44 </CDropdownMenu>
45 </CDropdown>
46</CButtonGroup>
1<CButtonGroup vertical role="group" aria-label="Vertical button group">
2 <CFormCheck
3 type="radio"
4 button={{ color: 'danger', variant: 'outline' }}
5 name="vbtnradio"
6 id="vbtnradio1"
7 autoComplete="off"
8 label="Radio 1"
9 defaultChecked
10 />
11 <CFormCheck
12 type="radio"
13 button={{ color: 'danger', variant: 'outline' }}
14 name="vbtnradio"
15 id="vbtnradio2"
16 autoComplete="off"
17 label="Radio 2"
18 />
19 <CFormCheck
20 type="radio"
21 button={{ color: 'danger', variant: 'outline' }}
22 name="vbtnradio"
23 id="vbtnradio3"
24 autoComplete="off"
25 label="Radio 3"
26 />
27</CButtonGroup>

API#

CButtonGroup#

1import { CButtonGroup } from '@coreui/bootstrap-react'
2// or
3import CButtonGroup from '@coreui/bootstrap-react/src/components/button-group/CButtonGroup'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-
sizeSize the component small or large.'sm' | 'lg'-
verticalCreate a set of buttons that appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.boolean-

CButtonToolbar#

1import { CButtonToolbar } from '@coreui/bootstrap-react'
2// or
3import CButtonToolbar from '@coreui/bootstrap-react/src/components/button-group/CButtonToolbar'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-