Skip to content

Commit

Permalink
let's merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Aug 3, 2018
1 parent ac8b27d commit 6fad1ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
13 changes: 6 additions & 7 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,10 @@ class Tooltip extends React.Component {
}
}

if (event.type === 'mouseenter' || event.type === 'mouseover') {
if (event.type === 'mouseover') {
this.internalState.hover = true;

if (childrenProps.onMouseEnter) {
childrenProps.onMouseEnter(event);
}
else if (childrenProps.onMouseOver) {
if (childrenProps.onMouseOver) {
childrenProps.onMouseOver(event);
}
}
Expand All @@ -193,7 +190,10 @@ class Tooltip extends React.Component {
};

handleOpen = event => {
if (!this.isControlled) {
// The mouseover event will trigger for every nested element in the tooltip.
// We can skip rerendering when the tooltip is already open.
// We are using the mouseover event instead of the mouseenter event to fix a hide/show issue.
if (!this.isControlled && !this.state.open) {
this.setState({ open: true });
}

Expand Down Expand Up @@ -321,7 +321,6 @@ class Tooltip extends React.Component {

if (!disableHoverListener) {
childrenProps.onMouseOver = this.handleEnter;
childrenProps.onMouseEnter = this.handleEnter;
childrenProps.onMouseLeave = this.handleLeave;
}

Expand Down
54 changes: 29 additions & 25 deletions packages/material-ui/src/Tooltip/Tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('<Tooltip />', () => {
wrapper.instance().childrenRef = document.createElement('div');
const children = wrapper.childAt(0).childAt(0);
assert.strictEqual(wrapper.state().open, false);
children.simulate('mouseEnter', { type: 'mouseenter' });
children.simulate('mouseOver', { type: 'mouseover' });
assert.strictEqual(wrapper.state().open, true);
children.simulate('mouseLeave', { type: 'mouseleave' });
assert.strictEqual(wrapper.state().open, false);
Expand All @@ -81,7 +81,7 @@ describe('<Tooltip />', () => {
const children = wrapper.childAt(0).childAt(0);
assert.strictEqual(handleRequestOpen.callCount, 0);
assert.strictEqual(handleClose.callCount, 0);
children.simulate('mouseEnter', { type: 'mouseenter' });
children.simulate('mouseOver', { type: 'mouseover' });
assert.strictEqual(handleRequestOpen.callCount, 1);
assert.strictEqual(handleClose.callCount, 0);
children.simulate('mouseLeave', { type: 'mouseleave' });
Expand All @@ -94,7 +94,7 @@ describe('<Tooltip />', () => {
wrapper.instance().childrenRef = document.createElement('div');
const children = wrapper.childAt(0).childAt(0);
assert.strictEqual(wrapper.state().open, false);
children.simulate('mouseEnter', { type: 'mouseenter' });
children.simulate('mouseOver', { type: 'mouseover' });
children.simulate('focus', { type: 'focus', persist });
clock.tick(0);
assert.strictEqual(wrapper.state().open, true);
Expand All @@ -112,7 +112,6 @@ describe('<Tooltip />', () => {
children.simulate('touchStart', { type: 'touchstart', persist });
children.simulate('touchEnd', { type: 'touchend', persist });
children.simulate('focus', { type: 'focus', persist });
children.simulate('mouseover', { type: 'mouseover' });
assert.strictEqual(wrapper.state().open, false);
});

Expand All @@ -122,7 +121,6 @@ describe('<Tooltip />', () => {
const children = wrapper.childAt(0).childAt(0);
children.simulate('touchStart', { type: 'touchstart', persist });
children.simulate('focus', { type: 'focus', persist });
children.simulate('mouseover', { type: 'mouseover' });
clock.tick(1e3);
assert.strictEqual(wrapper.state().open, true);
children.simulate('touchEnd', { type: 'touchend', persist });
Expand Down Expand Up @@ -164,26 +162,32 @@ describe('<Tooltip />', () => {
});

describe('prop: overrides', () => {
['onTouchStart', 'onTouchEnd', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur'].forEach(
name => {
it(`should be transparent for the ${name} event`, () => {
const handler = spy();
const wrapper = shallow(
<Tooltip title="Hello World">
<button type="submit" {...{ [name]: handler }}>
Hello World
</button>
</Tooltip>,
);
wrapper.instance().childrenRef = document.createElement('div');
const children = wrapper.childAt(0).childAt(0);
const type = name.slice(2).toLowerCase();
children.simulate(type, { type, persist });
clock.tick(0);
assert.strictEqual(handler.callCount, 1);
});
},
);
[
'onTouchStart',
'onTouchEnd',
'onMouseEnter',
'onMouseOver',
'onMouseLeave',
'onFocus',
'onBlur',
].forEach(name => {
it(`should be transparent for the ${name} event`, () => {
const handler = spy();
const wrapper = shallow(
<Tooltip title="Hello World">
<button type="submit" {...{ [name]: handler }}>
Hello World
</button>
</Tooltip>,
);
wrapper.instance().childrenRef = document.createElement('div');
const children = wrapper.childAt(0).childAt(0);
const type = name.slice(2).toLowerCase();
children.simulate(type, { type, persist });
clock.tick(0);
assert.strictEqual(handler.callCount, 1);
});
});
});

describe('disabled button warning', () => {
Expand Down

0 comments on commit 6fad1ca

Please sign in to comment.