Skip to content

Commit 0f92fc9

Browse files
sukanojohnleider
authored andcommitted
fix(VSelect): ignore keypress when readonly (#8194)
1 parent 3beea7c commit 0f92fc9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/vuetify/src/components/VSelect/VSelect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,10 @@ export default baseMixins.extend<options>().extend({
567567
}
568568
},
569569
onKeyPress (e: KeyboardEvent) {
570-
if (this.multiple) return
570+
if (
571+
this.multiple ||
572+
this.readonly
573+
) return
571574

572575
const KEYBOARD_LOOKUP_THRESHOLD = 1000 // milliseconds
573576
const now = performance.now()

packages/vuetify/src/components/VSelect/__tests__/VSelect4.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,27 @@ describe('VSelect.ts', () => {
253253
expect(wrapper.vm.internalValue).toBe('Foo')
254254
expect(wrapper.vm.$refs.menu.listIndex).toBe(-1)
255255
})
256+
257+
it('should not change value when typing on readonly field', async () => {
258+
const wrapper = mountFunction({
259+
propsData: {
260+
items: ['Foo', 'Bar', 'Fizz', 'Buzz'],
261+
readonly: true,
262+
value: 'Foo',
263+
},
264+
})
265+
266+
const input = wrapper.find('input')
267+
input.trigger('click')
268+
269+
await wrapper.vm.$nextTick()
270+
271+
expect(wrapper.vm.internalValue).toBe('Foo')
272+
273+
input.trigger('keypress', { key: 'b' })
274+
275+
await wrapper.vm.$nextTick()
276+
277+
expect(wrapper.vm.internalValue).toBe('Foo')
278+
})
256279
})

0 commit comments

Comments
 (0)