Skip to content
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

[ButtonBase] Document how to use cursor not-allowed #17778

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/src/pages/components/buttons/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,23 @@ Given that many of the interactive components rely on `ButtonBase`, you should b
able to take advantage of it everywhere.

Here is an [integration example with react-router](/guides/composition/#button).

## Limitations

### Cursor not-allowed

Material-UI's ButtonBase component set `pointer-events: none;` on disabled buttons.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
This tradeoff prevents the usage of a different disabled cursor.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

If you wish to use `not-allowed`, you need to remove the pointer event style and to handle these two edge cases:

1. You should prevent the interactions when the button is not implemented with an actual `<button>` element, for instance, a link `<a>` element. You can dodge the issue by specifically targeting the disabled state of the `<button>` element:

```css
.MuiButtonBase-root:disabled {
cursor: not-allowed;
pointer-events: auto;
}
```

2. You should add `pointer-events: none;` back when you need to display [tooltips on disabled elements](/components/tooltips/#disabled-elements)
2 changes: 1 addition & 1 deletion packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
'A disabled element does not fire events.',
"Tooltip needs to listen to the child element's events to display the title.",
'',
'Place a `div` container on top of the element.',
'Add a simple wrapper element like a `span`.',
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
].join('\n'),
);
}
Expand Down