Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add pull-right to a Button in React Bootstrap?

Tags:

I have the following JSX using React-Bootstrap:

<Button bsStyle="danger pull-right" bsSize="small" onClick={() => {alert('do stuff')}}>     <Glyphicon glyph="trash" /> </Button> 

This does work, but it shows a warning in the console:

Warning: Failed prop type: Invalid prop bsStyle of value danger pull-right supplied to Button, expected one of ["success","warning","danger","info","default","primary","link"].

What is the best way to add pull-right to the list of styles? I'd prefer not to have any warnings in my console.

like image 332
X-Istence Avatar asked Oct 24 '16 04:10

X-Istence


People also ask

How do I pull a button right in Bootstrap 5?

Answer: Use the text-right Classtext-right on the containing element to right align your Bootstrap buttons within a block box or grid column.

How do you align a button to the right in react?

To align a component to the center or right with React Material UI, we can add a flex container with the Grid component. We add the Grid component and add the container prop to make it a flexbox container. Then we set the justify prop to flex-end to align the child components on the right side.


2 Answers

If you take a look at React-Bootstrap Components, you'll see that prop bsStyle of component Button only accepts the following values:

"success", "warning", "danger", "info", "default", "primary", "link" 

based on its visual appearance as mentioned in the warning message. If you intend to use Bootstrap's pull-right class, just use the className attribute which will set the class of that component:

<Button className="pull-right" bsStyle="danger" bsSize="small" onClick={() => {alert('do stuff')}}>     <Glyphicon glyph="trash" /> </Button> 
like image 180
Andrew Li Avatar answered Sep 16 '22 23:09

Andrew Li


Bootstrap 4 Update

Now that React Bootstrap uses Bootstrap 4, use float-right, float-sm-right, etc.:

<Button className="float-right" bsStyle="danger" bsSize="small" onClick={() => {alert('do stuff')}}>     <Glyphicon glyph="trash" /> </Button> 
like image 43
Aaron Brager Avatar answered Sep 17 '22 23:09

Aaron Brager