-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
disabled buttons have pointer-events: none which prevent overriding of cursor property #14455
Comments
I'd hope the browser would make We could intercept the click event and stop propagation if the button is disabled. Not sure how touch devices will behave in that case. You can always unset the pointer-events style for your specific use case. |
@andyford What do you think of this change? --- a/packages/material-ui/src/ButtonBase/ButtonBase.js
+++ b/packages/material-ui/src/ButtonBase/ButtonBase.js
@@ -38,9 +38,11 @@ export const styles = {
borderStyle: 'none', // Remove Firefox dotted outline.
},
'&$disabled': {
- pointerEvents: 'none', // Disable link interactions
cursor: 'default',
},
+ 'a&$disabled': {
+ pointerEvents: 'none', // Disable link interactions
+ },
},
/* Styles applied to the root element if `disabled={true}`. */
disabled: {}, Do you want to work on it? |
@oliviertassinari Wouldn't that still make any button not rendered as |
@eps1lon Correct, maybe then? --- a/packages/material-ui/src/ButtonBase/ButtonBase.js
+++ b/packages/material-ui/src/ButtonBase/ButtonBase.js
@@ -38,9 +38,12 @@ export const styles = {
borderStyle: 'none', // Remove Firefox dotted outline.
},
'&$disabled': {
- pointerEvents: 'none', // Disable link interactions
+ pointerEvents: 'none', // Disable interactions
cursor: 'default',
},
+ 'button&$disabled': {
+ pointerEvents: 'auto',
+ },
},
/* Styles applied to the root element if `disabled={true}`. */
disabled: {}, |
I don't know to be honest. Every solution has some other flaws for some use cases. This solution would still not allow cursor styling for |
Alternatively, we can proxy the click events, but I think that it will require too much bundle size vs how often people will need it. |
I see this is a bit tricky. And making changes to this could cause surprises. So maybe it's enough to keep it as-is and add a note in the docs (this would have saved me a lot of time!). Perhaps warn people in the docs that |
What do you think of this change? --- a/packages/material-ui/src/ButtonBase/ButtonBase.js
+++ b/packages/material-ui/src/ButtonBase/ButtonBase.js
@@ -38,7 +38,6 @@ export const styles = {
borderStyle: 'none', // Remove Firefox dotted outline.
},
'&$disabled': {
- pointerEvents: 'none', // Disable link interactions
cursor: 'default',
},
},
@@ -69,6 +68,12 @@ class ButtonBase extends React.Component {
}
});
+ handleClick = event => {
+ if (this.props.onClick && !this.props.disabled) {
+ this.props.onClick(event);
+ }
+ };
+
handleMouseUp = createRippleHandler(this, 'MouseUp', 'stop');
handleMouseLeave = createRippleHandler(this, 'MouseLeave', 'stop', event => {
@@ -241,6 +246,7 @@ class ButtonBase extends React.Component {
focusRipple,
focusVisibleClassName,
onBlur,
+ onClick,
onFocus,
onFocusVisible,
onKeyDown,
@@ -291,6 +297,7 @@ class ButtonBase extends React.Component {
onMouseDown={this.handleMouseDown}
onMouseLeave={this.handleMouseLeave}
onMouseUp={this.handleMouseUp}
+ onClick={this.handleClick}
onTouchEnd={this.handleTouchEnd}
onTouchMove={this.handleTouchMove}
onTouchStart={this.handleTouchStart} |
@oliviertassinari I think without pointer events we end up polyfilling browser behavior for The suggestion from @andyford seems the most reasonable. Maybe add a demo and warn that allowing pointer events can make non button elements that are disabled clickable. |
@eps1lon I can't think of any wrong side effect.
Same limitation with ant: https://codesandbox.io/s/8yl2zv22rj |
I mean we can try it. I'm not familiar with touch behavior so I don't how enabling pointer-events interacts with touch devices. Would need to checkout a deploy preview. |
AFAIK, enabling pointer events/disabling works the same with touch behavior as with mouse events. Another problem with this issue is you can't add an informational At the moment I need to replace Granted, there is a workaround as mentioned, but it seems like something that should be considered. |
Hi.. I'll give this one a go, it's a small fix. |
@rob2d It's documented in https://material-ui.com/components/tooltips/#disabled-elements. |
I have added a new commit in #17778 to keep the current implementation and focus on documenting the limitation. Feedback welcome. |
What's wrong with #14455 (comment) ? I think the bigger issue is not being able to wrap disabled buttons with tooltips. IMO it's a good user experience to tell the user why a button is disabled. Just updating the docs isn't the best solution to this IMO |
@BenLorantfy We need |
Yeah never-mind I didn't realize the browser behaviour going on here. I understand why it's needed now 👍 |
Expected Behavior 🤔
adding
cursor: not-allowed;
(or other cursor types) to a the CSS of a disabled button should work for authorsCurrent Behavior 😯
CSS
cursor
property cannot be set because material-ui library setspointer-events: none;
on disabled buttons which has the side effect of not allowing thecursor
property to be setThe text was updated successfully, but these errors were encountered: