Tooltip should disappear after modal opening via router link
Tooltip stay open and jumps to pages top-left corner.
Nothing can close it, except mouseleave event on the wrapped element.
Link: https://codesandbox.io/s/ox9ro67yk6
related issues:
| Tech | Version |
|--------------|---------|
| Material-UI | v3.2.0 |
| React | v16.5.2 |
Hi Aleksandr,
update your button to
<Button
component={Link}
to="/someurl"
variant="contained"
color="primary"
aria-label="Verify"
>
HOVER ON ME, than click
</Button>
it will solve your problem.
I just update to V3.2.1. and I got same issue.
@JackyW83, better but still have one issue
https://codesandbox.io/s/yq902rmmrv
@mogadanez Regarding the first issue with this pattern:
<Tooltip title="Look at me">
<Button
component={props => <Link to={`/someurl`} {...props} />}
variant="contained"
color="primary"
aria-label="Verify"
>
HOVER ON ME, than click
</Button>
</Tooltip>
You get new DOM <a> element at each render as it's creating a new component.
The tooltip loses it's reference. A possible solution is to do:
--- a/packages/material-ui/src/Tooltip/Tooltip.js
+++ b/packages/material-ui/src/Tooltip/Tooltip.js
@@ -121,6 +121,13 @@ class Tooltip extends React.Component {
}
onRootRef = ref => {
+ // The children ref has changed. Something is wrong. Let's hide the tooltip.
+ if (ref !== null && this.childrenRef !== null && ref !== this.childrenRef && this.state.open) {
+ this.setState({
+ open: false,
+ })
+ }
+
this.childrenRef = ref;
};
I'm even wondering if we shouldn't warn about it.
Regarding the second issue. It looks like the "expected" behavior. The link button is the active element, the tooltip listens for the focus event. The tooltip is open when the focus move. It sounds like an acceptable tradeoff for me. Alternatively, you can disable the focus listener on the tooltip with disableFocusListener or disable the focus restore logic on the modal with disableRestoreFocus.
This also affects the Tooltip in the RTL button in the docs.
I have updated the provided sandbox, the first reported problem seems to be solved: https://codesandbox.io/s/tooltip-bug-igs7j.
Most helpful comment
Hi Aleksandr,
update your button to
it will solve your problem.