Material-ui: [Buttons] Disable elevation

Created on 24 Jun 2019  路  10Comments  路  Source: mui-org/material-ui

I have buttons that I don't want to have a box-shadow. Instead of custom CSS, using the elevation key would be ideal for me, as that's how we handle <Paper /> shadows

Button enhancement good first issue

Most helpful comment

@jawpio Simpler:

const theme = createMuiTheme({
  props: {
    MuiButton: {
      disableElevation: true,
    },
  },
});

All 10 comments

I鈥檓 not sure if this should be in the core library. I guess we should see what other users wants. I would close this in the mean time let鈥檚 see what @oliviertassinari thinks :)

@joshwooding I agree. Personally, I would override the box shadow, or start from the ButtonBase component.

It just seems kind of 'silly' for paper to accept elevation but nothing else. What sets Paper apart?

@MaxLeiter The Paper is used to abstract a surface, a surface has an elevation. In the light mode, the surface elevation defines the box shadow, in the dark mode, the elevation defines the box shadow and the background color. I don't think that the Button answer to the same requirements. But waiting for people upvotes sounds like a good tradeoff.

What about a disableElevation prop?

Capture d鈥檈虂cran 2019-12-05 a虁 23 45 15

````diff
diff --git a/packages/material-ui/src/Button/Button.d.ts b/packages/material-ui/src/Button/Button.d.ts
index 77fadc64e..b3b4b1ee4 100644
--- a/packages/material-ui/src/Button/Button.d.ts
+++ b/packages/material-ui/src/Button/Button.d.ts
@@ -8,6 +8,7 @@ export type ButtonTypeMap<

= ExtendButtonBaseTypeMap<{
props: P & {
color?: PropTypes.Color;

  • disableElevation?: boolean;
    disableFocusRipple?: boolean;
    endIcon?: React.ReactNode;
    fullWidth?: boolean;
    @@ -39,6 +40,7 @@ export type ButtonClassKey =
    | 'contained'
    | 'containedPrimary'
    | 'containedSecondary'
  • | 'disableElevation'
    | 'focusVisible'
    | 'disabled'
    | 'colorInherit'
    diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js
    index bdba5db1f..380389b47 100644
    --- a/packages/material-ui/src/Button/Button.js
    +++ b/packages/material-ui/src/Button/Button.js
    @@ -158,6 +158,25 @@ export const styles = theme => ({
    },
    },
    },
  • /* Styles applied to the root element if disableElevation={true}. */
  • disableElevation: {
  • boxShadow: 'none',
  • '&:hover': {
  • boxShadow: 'none',
  • '@media (hover: none)': {
  • boxShadow: 'none',
  • },
  • },
  • '&$focusVisible': {
  • boxShadow: 'none',
  • },
  • '&:active': {
  • boxShadow: 'none',
  • },
  • '&$disabled': {
  • boxShadow: 'none',
  • },
  • },
    /* Pseudo-class applied to the ButtonBase root element if the button is keyboard focused. /
    focusVisible: {},
    /
    Pseudo-class applied to the root element if disabled={true}. */
    @@ -251,6 +270,7 @@ const Button = React.forwardRef(function Button(props, ref) {
    color = 'default',
    component = 'button',
    disabled = false,
  • disableElevation = false,
    disableFocusRipple = false,
    endIcon: endIconProp,
    focusVisibleClassName,
    @@ -282,6 +302,7 @@ const Button = React.forwardRef(function Button(props, ref) {
    [classes[${variant}${capitalize(color)}]]: color !== 'default' && color !== 'inherit',
    [classes[${variant}Size${capitalize(size)}]]: size !== 'medium',
    [classes[size${capitalize(size)}]]: size !== 'medium',
  • [classes.disableElevation]: disableElevation,
    [classes.disabled]: disabled,
    [classes.fullWidth]: fullWidth,
    [classes.colorInherit]: color === 'inherit',
    @@ -332,6 +353,10 @@ Button.propTypes = {

    • If true, the button will be disabled.

      */

      disabled: PropTypes.bool,

  • /**

    • If true, no elevation is used.

  • */
  • disableElevation: PropTypes.bool,
    /**

    • If true, the keyboard focus ripple will be disabled.

    • disableRipple must also be true.

      ```

Can I work on this?

Guys, is it possible to override it on top level?

I tried following approach but no luck:

let theme = createMuiTheme({
  overrides: {
    MuiButton: {
      disableElevation: {
          boxShadow: 'none',
          '&:hover': {
            boxShadow: 'none',
            '@media (hover: none)': {
              boxShadow: 'none',
            },
          },
          '&$focusVisible': {
            boxShadow: 'none',
          },
          '&:active': {
            boxShadow: 'none',
          },
          '&$disabled': {
            boxShadow: 'none',
          },
      },
      root: {
        borderRadius: 2
      },
....

@jawpio Simpler:

const theme = createMuiTheme({
  props: {
    MuiButton: {
      disableElevation: true,
    },
  },
});

@jawpio Simpler:

const theme = createMuiTheme({
  props: {
    MuiButton: {
      disableElevation: true,
    },
  },
});

This just shows an error like in console:

Warning: Material-UI: you are trying to override a style that does not exist.
Fix the `disableElevation` key of `theme.overrides.MuiButton`. 

Any suggestion how we can use disableElevation to get it to work?
This one also does not work:

<MaterialButton disableElevation variant="contained" color="primary" >

Thanks in advance for suggestions

@negarineh theme.overrides !== theme.props

Was this page helpful?
0 / 5 - 0 ratings

Related issues

activatedgeek picture activatedgeek  路  3Comments

pola88 picture pola88  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

sys13 picture sys13  路  3Comments

mb-copart picture mb-copart  路  3Comments