Skip to content

Commit

Permalink
[Tooltip] Fix children mouse over detection (#32321)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-ngchakming authored Jul 11, 2022
1 parent 2c510d0 commit dc0e387
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/mui-material/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,14 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
return;
}

// Workaround for https://github.com/facebook/react/issues/7769
if (!childNode) {
setChildNode(event.currentTarget);
}
// Remove the title ahead of time.
// We don't want to wait for the next render commit.
// We would risk displaying two tooltips at the same time (native + this one).
if (childNode) {
else {
childNode.removeAttribute('title');
}

Expand Down Expand Up @@ -420,8 +424,6 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {

const handleFocus = (event) => {
// Workaround for https://github.com/facebook/react/issues/7769
// The autoFocus of React might trigger the event before the componentDidMount.
// We need to account for this eventuality.
if (!childNode) {
setChildNode(event.currentTarget);
}
Expand Down
17 changes: 17 additions & 0 deletions packages/mui-material/src/Tooltip/Tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,23 @@ describe('<Tooltip />', () => {
expect(getByRole('tooltip')).toBeVisible();
expect(handleFocus.callCount).to.equal(1);
});

it('should handle `onMouseOver` forwarding', () => {
const handleMouseOver = spy();
const { getByRole } = render(
<Tooltip enterDelay={100} title="Tooltip">
<button id="testChild" type="submit" onMouseOver={handleMouseOver}>
Hello World
</button>
</Tooltip>,
);

fireEvent.mouseOver(getByRole('button'));
clock.tick(100);

expect(getByRole('tooltip')).toBeVisible();
expect(handleMouseOver.callCount).to.equal(1);
});
});

describe('prop: delay', () => {
Expand Down

0 comments on commit dc0e387

Please sign in to comment.