Skip to content

Commit ac0cb3c

Browse files
committed
Add custom click handler for the tag component which ensures focus is always returned to the input, fixes #207
1 parent be1270e commit ac0cb3c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/ReactTags.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class ReactTags extends React.Component {
148148
}
149149
}
150150

151+
handleTagClick (i) {
152+
this.deleteTag(i)
153+
this.input.input.focus()
154+
}
155+
151156
addTag (tag) {
152157
if (tag.disabled) {
153158
return
@@ -184,7 +189,7 @@ class ReactTags extends React.Component {
184189
key={i}
185190
tag={tag}
186191
classNames={this.state.classNames}
187-
onDelete={this.deleteTag.bind(this, i)}
192+
onDelete={this.handleTagClick.bind(this, i)}
188193
/>
189194
))
190195

spec/ReactTags.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ describe('React Tags', () => {
420420
sinon.assert.calledWith(props.handleDelete, sinon.match(0))
421421
})
422422

423+
it('moves focus to the input when a tag is removed', () => {
424+
click($('.react-tags__selected-tag'))
425+
expect(document.activeElement).toEqual($('input'))
426+
})
427+
423428
it('deletes the last selected tag when backspace is pressed and query is empty', () => {
424429
type(''); key('backspace')
425430

0 commit comments

Comments
 (0)