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 all 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
33 changes: 33 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,36 @@ 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

The ButtonBase component sets `pointer-events: none;` on disabled buttons.
which prevents the appearance of a disabled cursor.

If you wish to use `not-allowed`, you have two options:

1. **CSS only**. You can remove the pointer events style on the disabled state of the `<button>` element:

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

However:

- You should add `pointer-events: none;` back when you need to display [tooltips on disabled elements](/components/tooltips/#disabled-elements)
- The cursor won't change if you render something other than a button element, for instance, a link `<a>` element.

2. **DOM change**. You can wrap the button:

```jsx
<span style={{ cursor: "not-allowed" }}>
<Button component={Link} disabled>disabled</Button>
</span>
```

This has the advantage of supporting any element, for instance, a link `<a>` element.
2 changes: 1 addition & 1 deletion docs/src/pages/components/tooltips/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ A tooltip can be interactive. It won't close when the user hovers over the toolt

## Disabled Elements

By default disabled elements like `<button>` do not trigger user interactions so a `Tooltip` will not activate on normal events like hover. To accommodate disabled elements, add a simple wrapper element like a `span`.
By default disabled elements like `<button>` do not trigger user interactions so a `Tooltip` will not activate on normal events like hover. To accommodate disabled elements, add a simple wrapper element, such as a `span`.

{{"demo": "pages/components/tooltips/DisabledTooltips.js"}}

Expand Down
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, such as a `span`.',
].join('\n'),
);
}
Expand Down