Skip to content

Commit ddf53d8

Browse files
add a regression test
1 parent 027d207 commit ddf53d8

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/material-ui/src/Tooltip/Tooltip.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
334334
}
335335

336336
const childrenProps = children.props;
337-
if (childrenProps.onFocus) {
337+
if (childrenProps.onFocus && event.currentTarget === childNode) {
338338
childrenProps.onFocus(event);
339339
}
340340
};
@@ -364,13 +364,17 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
364364
const childrenProps = children.props;
365365

366366
if (event.type === 'blur') {
367-
if (childrenProps.onBlur) {
367+
if (childrenProps.onBlur && event.currentTarget === childNode) {
368368
childrenProps.onBlur(event);
369369
}
370370
handleBlur(event);
371371
}
372372

373-
if (event.type === 'mouseleave' && childrenProps.onMouseLeave) {
373+
if (
374+
event.type === 'mouseleave' &&
375+
childrenProps.onMouseLeave &&
376+
event.currentTarget === childNode
377+
) {
374378
childrenProps.onMouseLeave(event);
375379
}
376380

packages/material-ui/src/Tooltip/Tooltip.test.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable jsx-a11y/mouse-events-have-key-events */
12
import React from 'react';
2-
import { assert } from 'chai';
3+
import { assert, expect } from 'chai';
34
import PropTypes from 'prop-types';
45
import { spy, useFakeTimers } from 'sinon';
56
import consoleErrorMock from 'test/utils/consoleErrorMock';
@@ -227,17 +228,17 @@ describe('<Tooltip />', () => {
227228
);
228229
const children = container.querySelector('#testChild');
229230
focusVisible(children);
230-
assert.strictEqual(document.body.querySelectorAll('[role="tooltip"]').length, 0);
231+
expect(document.body.querySelectorAll('[role="tooltip"]').length).to.equal(0);
231232
clock.tick(111);
232-
assert.strictEqual(document.body.querySelectorAll('[role="tooltip"]').length, 1);
233+
expect(document.body.querySelectorAll('[role="tooltip"]').length).to.equal(1);
233234
document.activeElement.blur();
234235
clock.tick(5);
235236
clock.tick(6);
236-
assert.strictEqual(document.body.querySelectorAll('[role="tooltip"]').length, 0);
237+
expect(document.body.querySelectorAll('[role="tooltip"]').length).to.equal(0);
237238

238239
focusVisible(children);
239240
// Bypass `enterDelay` wait, instant display.
240-
assert.strictEqual(document.body.querySelectorAll('[role="tooltip"]').length, 1);
241+
expect(document.body.querySelectorAll('[role="tooltip"]').length).to.equal(1);
241242
});
242243

243244
it('should take the leaveDelay into account', () => {
@@ -285,6 +286,19 @@ describe('<Tooltip />', () => {
285286
assert.strictEqual(handler.callCount, 1);
286287
});
287288
});
289+
290+
it('should ignore event from the tooltip', () => {
291+
const handleMouseOver = spy();
292+
const { getByRole } = render(
293+
<Tooltip {...defaultProps} open interactive>
294+
<button type="submit" onMouseOver={handleMouseOver}>
295+
Hello World
296+
</button>
297+
</Tooltip>,
298+
);
299+
fireEvent.mouseOver(getByRole('tooltip'));
300+
expect(handleMouseOver.callCount).to.equal(0);
301+
});
288302
});
289303

290304
describe('disabled button warning', () => {

0 commit comments

Comments
 (0)