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

Fix keyboard focus not returning to input after clear #7

Merged
merged 1 commit into from
Feb 1, 2023
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: 2 additions & 0 deletions src/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ export default {
})
)
this.$emit('option:deselected', option)
this.searchEl.focus()
},

/**
Expand All @@ -1047,6 +1048,7 @@ export default {
*/
clearSelection() {
this.updateValue(this.multiple ? [] : null)
this.searchEl.focus()
},

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/Deselecting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ describe('Removing values', () => {
expect(deselect).not.toHaveBeenCalledWith('one')
})

it('should return focus to the search input after deselect', () => {
const Select = selectWithProps({
multiple: true,
options: ['one', 'two', 'three'],
value: ['one'],
})

const deselect = Select.findComponent({ ref: 'deselectButtons' })
deselect.trigger('click')

const input = Select.findComponent({ ref: 'search' })
expect(document.activeElement).toEqual(input.element)
})

describe('Clear button', () => {
it('should be displayed on single select when value is selected', () => {
const Select = selectWithProps({
Expand Down Expand Up @@ -156,5 +170,18 @@ describe('Removing values', () => {
'disabled'
)
})

it('should return focus to the search input after clear', () => {
const Select = selectWithProps({
options: ['foo', 'bar'],
value: 'foo',
})

const clear = Select.findComponent({ ref: 'clearButton' })
clear.trigger('click')

const input = Select.findComponent({ ref: 'search' })
expect(document.activeElement).toEqual(input.element)
})
})
})