From 3e054e378e93ca64b7cbec02748593153869083c Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Tue, 8 Oct 2019 10:46:55 +0200 Subject: [PATCH] simplest possible solution --- docs/src/pages/components/buttons/buttons.md | 20 +++++ .../components/tooltips/DisabledTooltips.tsx | 4 +- .../src/pages/components/tooltips/tooltips.md | 6 +- .../src/ButtonBase/ButtonBase.d.ts | 2 +- .../material-ui/src/ButtonBase/ButtonBase.js | 90 ++++++++----------- packages/material-ui/src/Tooltip/Tooltip.js | 2 +- 6 files changed, 65 insertions(+), 59 deletions(-) diff --git a/docs/src/pages/components/buttons/buttons.md b/docs/src/pages/components/buttons/buttons.md index fb9ac08d88bf89..50ef343ed22e95 100644 --- a/docs/src/pages/components/buttons/buttons.md +++ b/docs/src/pages/components/buttons/buttons.md @@ -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. +This tradeoff prevents the usage of a different disabled cursor. + +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 ` - + ); } diff --git a/docs/src/pages/components/tooltips/tooltips.md b/docs/src/pages/components/tooltips/tooltips.md index f34d80a4f4ba5b..5a9ce50f614bcd 100644 --- a/docs/src/pages/components/tooltips/tooltips.md +++ b/docs/src/pages/components/tooltips/tooltips.md @@ -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 ` - + ``` diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.d.ts b/packages/material-ui/src/ButtonBase/ButtonBase.d.ts index 0dcda8769112dc..cdfcde59733aec 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.d.ts +++ b/packages/material-ui/src/ButtonBase/ButtonBase.d.ts @@ -45,7 +45,7 @@ export type ButtonBaseProps< P = {} > = OverrideProps, D>; -export type ButtonBaseClassKey = 'root' | 'a' | 'disabled' | 'focusVisible'; +export type ButtonBaseClassKey = 'root' | 'disabled' | 'focusVisible'; export interface ButtonBaseActions { focusVisible(): void; diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.js b/packages/material-ui/src/ButtonBase/ButtonBase.js index 8a302b941adc0a..86348d95c7d28e 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.js +++ b/packages/material-ui/src/ButtonBase/ButtonBase.js @@ -10,9 +10,6 @@ import NoSsr from '../NoSsr'; import { useIsFocusVisible } from '../utils/focusVisible'; import TouchRipple from './TouchRipple'; -const ConditionalWrapper = ({ condition, wrapper, children }) => - condition ? wrapper(children) : children; - export const styles = { /* Styles applied to the root element. */ root: { @@ -40,18 +37,13 @@ export const styles = { '&::-moz-focus-inner': { borderStyle: 'none', // Remove Firefox dotted outline. }, - '&$a$disabled': { - display: 'inline-block' /* For IE11/ MS Edge bug */, - pointerEvents: 'none', - textDecoration: 'none', + '&$disabled': { + pointerEvents: 'none', // Disable link interactions + cursor: 'default', }, }, - /* Styles applied to a link. */ - a: {}, /* Pseudo-class applied to the root element if `disabled={true}`. */ - disabled: { - cursor: 'not-allowed', - }, + disabled: {}, /* Pseudo-class applied to the root element if keyboard focused. */ focusVisible: {}, }; @@ -264,47 +256,41 @@ const ButtonBase = React.forwardRef(function ButtonBase(props, ref) { const handleRef = useForkRef(handleUserRef, handleOwnRef); return ( - {wrapperChildren}} + - - {children} - {!disableRipple && !disabled ? ( - - {/* TouchRipple is only needed client-side, x2 boost on the server. */} - - - ) : null} - - + {children} + {!disableRipple && !disabled ? ( + + {/* TouchRipple is only needed client-side, x2 boost on the server. */} + + + ) : null} + ); }); diff --git a/packages/material-ui/src/Tooltip/Tooltip.js b/packages/material-ui/src/Tooltip/Tooltip.js index e21e198672448b..61c3febb6aba4b 100644 --- a/packages/material-ui/src/Tooltip/Tooltip.js +++ b/packages/material-ui/src/Tooltip/Tooltip.js @@ -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 `div`.', ].join('\n'), ); }