Skip to content

Commit

Permalink
Merge pull request #7 from nextcloud-deps/fix/a11y-clear-kb-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal authored Feb 1, 2023
2 parents d7d042a + 12466c9 commit 9ef870b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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)
})
})
})

0 comments on commit 9ef870b

Please sign in to comment.