I have this code here :
I am trying to have 3 small square buttons with + and - sign and one in the middle with a digit. I am using material. The buttons now are rectangular and too big for my app. My problem is I just can't have them square and resize them. I have tried a lot of things but it doesn't work. Thanks
<Grid item>
<Button onClick={this.up} variant="outlined">
<Add color="secondary" />
</Button>
<Button style={{ padding: "11px 0px" }} variant="outlined">
{this.state.quantity < 1 ? 0 : this.state.quantity}
</Button>
<Button onClick={this.down} variant="outlined">
<Remove color="secondary" />
</Button>
</Grid>
To resize a React Material UI button, we set can the style prop of the Button to an object that sets the dimensions of the button. We add a button by adding the Button component. And we set the style prop of the button to an object that has the maxWidth , maxHeight , minWidth and minHeight properties.
Button size To change the size of the default Button to small Button, set the cssClass property to e-small .
The interface of the theme itself is different, but that seems to be about it there. Material UI implements Material UI by default and this is the main reason why it's hard to customize. Too much to change. I guess this is one of the reasons why there are not that many custom themes available for this library.
You could add max/min width/height style options.
For instance:
<Button style={{maxWidth: '30px', maxHeight: '30px', minWidth: '30px', minHeight: '30px'}}/>
In this case button always will look like a square and have a fix size (30px).
I assume you have a <Grid container>
around the elements you posted. MUI Grids are designed to fill up the space and manage column widths. Seems like you probably need to restrict the outer <Grid container>
to the total width you want the columns to span.
Also, note if you want to override all <Buttons>
, do so in the theme...
createMuiTheme({
overrides: {
MuiButton: {
outlined: {
borderRadius: '0'
}
}
}
})
Material UI 5.x.x
createTheme({
components: {
MuiButton: {
styleOverrides: {
root: { minWidth: 0 }
}
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With