Skip to content

Commit

Permalink
fix(VList): don't trigger keyboard events on disabled items (#15339)
Browse files Browse the repository at this point in the history
resolves #15322

Co-authored-by: lampdev <orders@lampdev.com>
  • Loading branch information
lampdev and lampdev committed Jun 29, 2022
1 parent ff519c6 commit 817df79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vuetify/src/components/VList/VListItem.ts
Expand Up @@ -168,10 +168,12 @@ export default baseMixins.extend<options>().extend({
data[this.to ? 'nativeOn' : 'on'] = {
...data[this.to ? 'nativeOn' : 'on'],
keydown: (e: KeyboardEvent) => {
/* istanbul ignore else */
if (e.keyCode === keyCodes.enter) this.click(e)
if (!this.disabled) {
/* istanbul ignore else */
if (e.keyCode === keyCodes.enter) this.click(e)

this.$emit('keydown', e)
this.$emit('keydown', e)
}
},
}

Expand Down
12 changes: 12 additions & 0 deletions packages/vuetify/src/components/VList/__tests__/VListItem.spec.ts
Expand Up @@ -234,4 +234,16 @@ describe('VListItem.ts', () => {
wrapper2.vm.toggle()
expect(wrapper2.vm.isActive).toBeTruthy()
})

it('should not react to keydown.enter when disabled', () => {
const click = jest.fn()
const wrapper = mountFunction({
methods: { click },
propsData: { disabled: true },
})

wrapper.trigger('keydown.enter')

expect(click).not.toHaveBeenCalled()
})
})

0 comments on commit 817df79

Please sign in to comment.