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

[Tooltip] Support tooltips for disabled buttons #22937

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 1 addition & 3 deletions docs/src/pages/components/tooltips/DisabledTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Tooltip from '@material-ui/core/Tooltip';
export default function DisabledTooltips() {
return (
<Tooltip title="You don't have permission to do this">
<span>
<Button disabled>A Disabled Button</Button>
</span>
<Button disabled>A Disabled Button</Button>
</Tooltip>
);
}
4 changes: 1 addition & 3 deletions docs/src/pages/components/tooltips/DisabledTooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Tooltip from '@material-ui/core/Tooltip';
export default function DisabledTooltips() {
return (
<Tooltip title="You don't have permission to do this">
<span>
<Button disabled>A Disabled Button</Button>
</span>
<Button disabled>A Disabled Button</Button>
</Tooltip>
);
}
1 change: 0 additions & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const styles = {
borderStyle: 'none', // Remove Firefox dotted outline.
},
'&$disabled': {
pointerEvents: 'none', // Disable link interactions
cursor: 'default',
},
'@media print': {
Expand Down
44 changes: 24 additions & 20 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -387,27 +387,31 @@ 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) => {
if (children.props.onTouchEnd) {
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(() => {
Expand Down Expand Up @@ -501,12 +505,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);
}
}

Expand Down