Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooltip] New warning message #8988

Merged
merged 1 commit into from Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Tooltip/Tooltip.js
Expand Up @@ -228,6 +228,22 @@ class Tooltip extends React.Component<ProvidedProps & Props, State> {
}
}

componentDidMount() {
warning(
!this.children ||
!this.children.disabled ||
// $FlowFixMe
!this.children.tagName.toLowerCase() === 'button',
[
'Material-UI: you are providing a disabled button children to the Tooltip component.',
'A disabled element do not fire events.',
'But the Tooltip needs to listen to the children element events to display the title.',
'',
'Place a `div` over top of the element.',
].join('\n'),
);
}

componentWillUnmount() {
clearTimeout(this.enterTimer);
clearTimeout(this.leaveTimer);
Expand All @@ -239,6 +255,7 @@ class Tooltip extends React.Component<ProvidedProps & Props, State> {
touchTimer = null;
isControlled = null;
popper = null;
children = null;
ignoreNonTouchEvents = false;

handleResize = debounce(() => {
Expand Down Expand Up @@ -421,7 +438,8 @@ class Tooltip extends React.Component<ProvidedProps & Props, State> {
: childrenProp
}
ref={node => {
targetProps.ref(findDOMNode(node));
this.children = findDOMNode(node);
targetProps.ref(this.children);
}}
/>
)}
Expand Down
24 changes: 24 additions & 0 deletions src/Tooltip/Tooltip.spec.js
Expand Up @@ -7,6 +7,7 @@ import { spy, useFakeTimers } from 'sinon';
import { Target, Popper } from 'react-popper';
import { ShallowWrapper } from 'enzyme';
import { createShallow, createMount, getClasses, unwrap } from '../test-utils';
import consoleErrorMock from '../../test/utils/consoleErrorMock';
import createMuiTheme from '../styles/createMuiTheme';
import Tooltip from './Tooltip';

Expand Down Expand Up @@ -315,4 +316,27 @@ describe('<Tooltip />', () => {
assert.strictEqual(handleUpdate.callCount, 1);
});
});

describe('disabled button warning', () => {
before(() => {
consoleErrorMock.spy();
});

after(() => {
consoleErrorMock.reset();
});

it('should raise a warning when we can listen to events', () => {
mount(
<Tooltip title="Hello World">
<button disabled>Hello World</button>
</Tooltip>,
);
assert.strictEqual(consoleErrorMock.callCount(), 1, 'should call console.error');
assert.match(
consoleErrorMock.args()[0][0],
/Material-UI: you are providing a disabled button children to the Tooltip component/,
);
});
});
});