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

added check prop 'visible' on undefined #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class Tooltip extends Component {
placement, align,
destroyTooltipOnHide,
defaultVisible, getTooltipContainer,
visible,
...restProps,
} = this.props;
const extraProps = { ...restProps };
if ('visible' in this.props) {
extraProps.popupVisible = this.props.visible;
if (typeof visible !== 'undefined') {
extraProps.popupVisible = visible;
}
return (<Trigger
popupClassName={overlayClassName}
Expand Down
32 changes: 32 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ const verifyContent = (wrapper, content) => {
};

describe('rc-tooltip', () => {
describe('show when set prop visible', () => {
it('is boolean', () => {
const wrapper = mount(
<Tooltip
visible
overlay={<strong className="x-content">Tooltip content</strong>}
>
<div className="target">Click this</div>
</Tooltip>
);

expect(wrapper.find('.x-content').text()).toBe('Tooltip content');
expect(wrapper.instance().getPopupDomNode()).toBeTruthy();
});

it('is undefined', () => {
const wrapper = mount(
<Tooltip
visible={undefined}
trigger={['click']}
placement="left"
overlay={<strong className="x-content">Tooltip content</strong>}
>
<div className="target">Click this</div>
</Tooltip>
);
wrapper.find('.target').simulate('click');
verifyContent(wrapper, 'Tooltip content');
});
});


describe('shows and hides itself on click', () => {
it('using an element overlay', () => {
const wrapper = mount(
Expand Down