From faaba7e0c0f29018be3a6614ef8c5dec06f93b0d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 8 Oct 2020 12:37:01 +0200 Subject: [PATCH 1/2] [Tooltip] Support tooltips for disabled buttons --- .../pages/components/tooltips/DisabledTooltips.js | 4 +--- .../pages/components/tooltips/DisabledTooltips.tsx | 4 +--- packages/material-ui/src/ButtonBase/ButtonBase.js | 1 - packages/material-ui/src/Tooltip/Tooltip.js | 12 ++++++------ 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/docs/src/pages/components/tooltips/DisabledTooltips.js b/docs/src/pages/components/tooltips/DisabledTooltips.js index 7bad994065773c..72152d65122a13 100644 --- a/docs/src/pages/components/tooltips/DisabledTooltips.js +++ b/docs/src/pages/components/tooltips/DisabledTooltips.js @@ -5,9 +5,7 @@ import Tooltip from '@material-ui/core/Tooltip'; export default function DisabledTooltips() { return ( - - - + ); } diff --git a/docs/src/pages/components/tooltips/DisabledTooltips.tsx b/docs/src/pages/components/tooltips/DisabledTooltips.tsx index 7bad994065773c..72152d65122a13 100644 --- a/docs/src/pages/components/tooltips/DisabledTooltips.tsx +++ b/docs/src/pages/components/tooltips/DisabledTooltips.tsx @@ -5,9 +5,7 @@ import Tooltip from '@material-ui/core/Tooltip'; export default function DisabledTooltips() { return ( - - - + ); } diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.js b/packages/material-ui/src/ButtonBase/ButtonBase.js index 400b1f592bed7b..229bd1f488e429 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.js +++ b/packages/material-ui/src/ButtonBase/ButtonBase.js @@ -36,7 +36,6 @@ export const styles = { borderStyle: 'none', // Remove Firefox dotted outline. }, '&$disabled': { - pointerEvents: 'none', // Disable link interactions cursor: 'default', }, '@media print': { diff --git a/packages/material-ui/src/Tooltip/Tooltip.js b/packages/material-ui/src/Tooltip/Tooltip.js index 6e6c50da4a7f43..8fb5eb8b81817f 100644 --- a/packages/material-ui/src/Tooltip/Tooltip.js +++ b/packages/material-ui/src/Tooltip/Tooltip.js @@ -263,8 +263,8 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) { const handleEnter = (forward = true) => (event) => { const childrenProps = children.props; - if (event.type === 'mouseover' && childrenProps.onMouseOver && forward) { - childrenProps.onMouseOver(event); + if (event.type === 'pointerenter' && childrenProps.onPointerEnter && forward) { + childrenProps.onPointerEnter(event); } if (ignoreNonTouchEvents.current && event.type !== 'touchstart') { @@ -501,12 +501,12 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) { } if (!disableHoverListener) { - childrenProps.onMouseOver = handleEnter(); - childrenProps.onMouseLeave = handleLeave(); + childrenProps.onPointerEnter = handleEnter(); + childrenProps.onPointerLeave = handleLeave(); if (!disableInteractive) { - interactiveWrapperListeners.onMouseOver = handleEnter(false); - interactiveWrapperListeners.onMouseLeave = handleLeave(false); + interactiveWrapperListeners.onPointerEnter = handleEnter(false); + interactiveWrapperListeners.onPointerLeave = handleLeave(false); } } From 481a60c2ed8f79f6dbdfc2dd0eed4d1775f51095 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Thu, 15 Oct 2020 16:53:50 +0200 Subject: [PATCH 2/2] Dont handle touch if we already handle pointers --- packages/material-ui/src/Tooltip/Tooltip.js | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/material-ui/src/Tooltip/Tooltip.js b/packages/material-ui/src/Tooltip/Tooltip.js index 8fb5eb8b81817f..b103ff5eb59cc4 100644 --- a/packages/material-ui/src/Tooltip/Tooltip.js +++ b/packages/material-ui/src/Tooltip/Tooltip.js @@ -387,14 +387,16 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) { }; const handleTouchStart = (event) => { - detectTouchStart(event); - clearTimeout(leaveTimer.current); - clearTimeout(closeTimer.current); - clearTimeout(touchTimer.current); - event.persist(); - touchTimer.current = setTimeout(() => { - handleEnter()(event); - }, enterTouchDelay); + if (typeof PointerEvent === 'undefined') { + detectTouchStart(event); + clearTimeout(leaveTimer.current); + clearTimeout(closeTimer.current); + clearTimeout(touchTimer.current); + event.persist(); + touchTimer.current = setTimeout(() => { + handleEnter()(event); + }, enterTouchDelay); + } }; const handleTouchEnd = (event) => { @@ -402,12 +404,14 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) { children.props.onTouchEnd(event); } - clearTimeout(touchTimer.current); - clearTimeout(leaveTimer.current); - event.persist(); - leaveTimer.current = setTimeout(() => { - handleClose(event); - }, leaveTouchDelay); + if (typeof PointerEvent === 'undefined') { + clearTimeout(touchTimer.current); + clearTimeout(leaveTimer.current); + event.persist(); + leaveTimer.current = setTimeout(() => { + handleClose(event); + }, leaveTouchDelay); + } }; React.useEffect(() => {