Skip to content

Commit

Permalink
[ButtonBase] Document how to use cursor not-allowed (#17778)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-tate authored and oliviertassinari committed Oct 11, 2019
1 parent b69bd04 commit 2e51d2a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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

0 comments on commit 2e51d2a

Please sign in to comment.