Skip to content

Commit 18ab0d9

Browse files
priyanshu92mrchief
authored andcommitted
fix: Do not toggle dropwdown on pill removal (#141) 🐛
fix: Do not toggle dropwdown on pill removal
1 parent c0ee452 commit 18ab0d9

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

docs/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tag/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class Tag extends PureComponent {
1313
onDelete: PropTypes.func
1414
}
1515

16-
handleClick = () => {
16+
handleClick = e => {
1717
const { id, onDelete } = this.props
18-
18+
e.stopPropagation()
19+
e.nativeEvent.stopImmediatePropagation()
1920
onDelete(id)
2021
}
2122

src/tag/index.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,33 @@ import toJson from 'enzyme-to-json'
66

77
import Tag from './index'
88

9+
const nativeEvent = { nativeEvent: { stopImmediatePropagation: () => {} } }
10+
911
test('renders label when passed in', t => {
1012
const wrapper = toJson(shallow(<Tag label="hello" id="abc" />))
1113
t.snapshot(wrapper)
1214
})
1315

16+
test('call stopPropagation and stopImmediatePropagation when pill is closed', t => {
17+
const onDelete = spy()
18+
const wrapper = mount(<Tag label="hello" id="abc" onDelete={onDelete} />)
19+
const event = {
20+
type: 'click',
21+
stopPropagation: spy(),
22+
nativeEvent: {
23+
stopImmediatePropagation: spy()
24+
}
25+
}
26+
wrapper.find('.tag-remove').prop('onClick')(event)
27+
t.true(event.stopPropagation.called)
28+
t.true(event.nativeEvent.stopImmediatePropagation.called)
29+
})
30+
31+
1432
test('call onDelete handler when pill is closed', t => {
1533
const onDelete = spy()
1634
const wrapper = mount(<Tag label="hello" id="abc" onDelete={onDelete} />)
17-
wrapper.find('.tag-remove').simulate('click')
35+
wrapper.find('.tag-remove').simulate('click', nativeEvent)
1836
t.true(onDelete.calledWith('abc'))
1937
})
2038

@@ -24,6 +42,6 @@ test('should not cause form submit', t => {
2442
const wrapper = mount(<form onSubmit={onSubmit}>
2543
<Tag label="hello" id="abc" onDelete={onDelete} />
2644
</form>)
27-
wrapper.find('.tag-remove').simulate('click')
45+
wrapper.find('.tag-remove').simulate('click', nativeEvent)
2846
t.false(onSubmit.called)
2947
})

0 commit comments

Comments
 (0)