-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Buttons] Disable elevation #16357
Comments
I’m 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’s 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 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:
|
@jawpio Simpler: const theme = createMuiTheme({
props: {
MuiButton: {
disableElevation: true,
},
},
}); |
This just shows an error like in console:
Any suggestion how we can use
Thanks in advance for suggestions |
@negarineh |
@oliviertassinari Is there a way to use |
@cmacdonnacha you can customize the CSS directly. |
@oliviertassinari Yea I have added some css to my main
|
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 />
shadowsThe text was updated successfully, but these errors were encountered: