React Bootstrap — Button Groups

Image for post
Image for post
Photo by Andrés Dallimonti on Unsplash

React Bootstrap is one version of Bootstrap made for React.

It’s a set of React components that have Bootstrap styles.

In this article, we’ll look at how to work with React Bootstrap button groups.

Button Groups

We can create button groups to group buttons together on a single line.

For instance, we can write:

We imported the ButtonGroup component to create a button group with Button s inside.

Button Toolbar

A button toolbar is a container for a set of button groups.

For instance, we can write:

We have buttons in the button groups.

Then the buttons groups are in the ButtonToolbar .

We add the mr-2 class to give the groups some margins on the right.

We can mix input and button groups on our toolbars.

For example, we can write:

We have an InputGroup beside out ButtonGroup .

They’ll be displayed side by side if the screen is wide enough.

Sizing

We can change the size of the button groups.

For instance, we can write:

We put buttons in our button groups.

The size prop lets us change the size of all the buttons.

Nesting

We can place DropdownButtons in ButtonGroup s.

For instance, we can write:

We put the Button s in the ButtonGroup with the DropdownButton beside it.

Inside the DropdownButton , we have Dropdown.Item components that we can click on.

The title prop has the dropdown button’s text content.

Vertical Variation

We can make the buttons display vertically if we add a vertical prop to our ButtonGroup .

For example, we can write:

Now everything is displayed vertically.

Image for post
Image for post
Photo by Loïc Fürhoff on Unsplash

Conclusion

We can use button groups to group buttons together.

They can be vertical or horizontal.

The size can also vary according to the props.

Written by

Web developer. Subscribe to my email list now at http://jauyeung.net/subscribe/. Email me at hohanga@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store