Skip to content
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
2 changes: 1 addition & 1 deletion docs/bundle.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/tag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Tag extends PureComponent {
onDelete: PropTypes.func
}

handleClick = () => {
handleClick = e => {
const { id, onDelete } = this.props

e.stopPropagation()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remember why but I think we also need to add e.stopImmediatePropagation() too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. We can use stopImmediatePropagation() because it implicitly calls stopPropagation(). I'll update the code.

e.nativeEvent.stopImmediatePropagation()
onDelete(id)
}

Expand Down
22 changes: 20 additions & 2 deletions src/tag/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,33 @@ import toJson from 'enzyme-to-json'

import Tag from './index'

const nativeEvent = { nativeEvent: { stopImmediatePropagation: () => {} } }

test('renders label when passed in', t => {
const wrapper = toJson(shallow(<Tag label="hello" id="abc" />))
t.snapshot(wrapper)
})

test('call stopPropagation and stopImmediatePropagation when pill is closed', t => {
const onDelete = spy()
const wrapper = mount(<Tag label="hello" id="abc" onDelete={onDelete} />)
const event = {
type: 'click',
stopPropagation: spy(),
nativeEvent: {
stopImmediatePropagation: spy()
}
}
wrapper.find('.tag-remove').prop('onClick')(event)
t.true(event.stopPropagation.called)
t.true(event.nativeEvent.stopImmediatePropagation.called)
})


test('call onDelete handler when pill is closed', t => {
const onDelete = spy()
const wrapper = mount(<Tag label="hello" id="abc" onDelete={onDelete} />)
wrapper.find('.tag-remove').simulate('click')
wrapper.find('.tag-remove').simulate('click', nativeEvent)
t.true(onDelete.calledWith('abc'))
})

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