From 08fb442716b86d524a444686cb839ccd3cdb634b Mon Sep 17 00:00:00 2001 From: ivan-ngchakming Date: Sat, 16 Apr 2022 16:14:10 +0800 Subject: [PATCH 1/4] fix: not open on hover --- packages/mui-material/src/Tooltip/Tooltip.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/mui-material/src/Tooltip/Tooltip.js b/packages/mui-material/src/Tooltip/Tooltip.js index 86129bd76aebd6..59b4c5f7583dbf 100644 --- a/packages/mui-material/src/Tooltip/Tooltip.js +++ b/packages/mui-material/src/Tooltip/Tooltip.js @@ -372,10 +372,16 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) { return; } + // 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); + } // 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'); } From e71f5b3817292a0c3aa86ebf4a4d31e7407a5b7f Mon Sep 17 00:00:00 2001 From: ivan-ngchakming Date: Sat, 16 Apr 2022 21:28:03 +0800 Subject: [PATCH 2/4] removed incorrect comments --- packages/mui-material/src/Tooltip/Tooltip.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/mui-material/src/Tooltip/Tooltip.js b/packages/mui-material/src/Tooltip/Tooltip.js index 59b4c5f7583dbf..111403e673fbb1 100644 --- a/packages/mui-material/src/Tooltip/Tooltip.js +++ b/packages/mui-material/src/Tooltip/Tooltip.js @@ -372,9 +372,6 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) { return; } - // 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); } From ab8444833da352e78209acbadc5a2c49f48bdf3f Mon Sep 17 00:00:00 2001 From: ivan-ngchakming Date: Sun, 17 Apr 2022 12:00:16 +0800 Subject: [PATCH 3/4] updated comments again --- packages/mui-material/src/Tooltip/Tooltip.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/mui-material/src/Tooltip/Tooltip.js b/packages/mui-material/src/Tooltip/Tooltip.js index 111403e673fbb1..0d92a708e2a318 100644 --- a/packages/mui-material/src/Tooltip/Tooltip.js +++ b/packages/mui-material/src/Tooltip/Tooltip.js @@ -372,6 +372,7 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) { return; } + // Workaround for https://github.com/facebook/react/issues/7769 if (!childNode) { setChildNode(event.currentTarget); } @@ -423,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); } From 18ffb5f7f9ce5d25df49a62053d0f651fbee6efd Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Mon, 11 Jul 2022 09:59:10 +0100 Subject: [PATCH 4/4] Add test --- .../mui-material/src/Tooltip/Tooltip.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/mui-material/src/Tooltip/Tooltip.test.js b/packages/mui-material/src/Tooltip/Tooltip.test.js index 420d32cd7e2c88..bb61d1d4d066ee 100644 --- a/packages/mui-material/src/Tooltip/Tooltip.test.js +++ b/packages/mui-material/src/Tooltip/Tooltip.test.js @@ -433,6 +433,23 @@ describe('', () => { expect(getByRole('tooltip')).toBeVisible(); expect(handleFocus.callCount).to.equal(1); }); + + it('should handle `onMouseOver` forwarding', () => { + const handleMouseOver = spy(); + const { getByRole } = render( + + + , + ); + + fireEvent.mouseOver(getByRole('button')); + clock.tick(100); + + expect(getByRole('tooltip')).toBeVisible(); + expect(handleMouseOver.callCount).to.equal(1); + }); }); describe('prop: delay', () => {