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

Add e.stopPropagation() in the onToggle in the HelpBubble component #347

Merged
merged 1 commit into from
Dec 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/HelpBubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class HelpBubble extends React.Component {
};
}

toggle = () => {
toggle = (e) => {
e.stopPropagation();
this.setState({ isOpen: !this.state.isOpen });
};

Expand All @@ -45,7 +46,7 @@ class HelpBubble extends React.Component {
<span className={className} style={style}>
<Icon
name="question-circle"
onClick={this.toggle}
onClick={e => this.toggle(e)}
id={this.id}
className="text-primary"
/>
Expand Down
9 changes: 6 additions & 3 deletions test/components/HelpBubble.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import assert from 'assert';
import sinon from 'sinon';
import { shallow, mount } from 'enzyme';
import {
Popover,
Expand Down Expand Up @@ -29,9 +30,10 @@ describe('<HelpBubble />', () => {
});

it('should open popover when toggled', () => {
const event = { stopPropagation: sinon.stub() };
const component = shallow(<HelpBubble title="hi" />);
assert.equal(component.find(Popover).prop('isOpen'), false);
component.find(Icon).simulate('click');
component.find(Icon).simulate('click', event);
assert.equal(component.find(Popover).prop('isOpen'), true);
});

Expand All @@ -56,12 +58,13 @@ describe('<HelpBubble />', () => {
});

it('should be closed after you toggle both the icon and the popover', done => {
const event = { stopPropagation: sinon.stub() };
const component = shallow(<HelpBubble title="hi" />);
assert.equal(component.find(Popover).prop('isOpen'), false);
component.find(Icon).simulate('click');
component.find(Icon).simulate('click', event);
assert.equal(component.find(Popover).prop('isOpen'), true);
component.find(Popover).prop('toggle')();
component.find(Icon).simulate('click');
component.find(Icon).simulate('click', event);
setTimeout(() => {
assert.equal(component.find(Popover).prop('isOpen'), false);
done();
Expand Down