Skip to content

Commit

Permalink
fix(VSelect): close menu on tab out
Browse files Browse the repository at this point in the history
fixes #5774
  • Loading branch information
johnleider committed Dec 12, 2018
1 parent d3bc050 commit 8a2a1a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/vuetify/src/components/VSelect/VSelect.js
Expand Up @@ -256,11 +256,12 @@ export default {

methods: {
/** @public */
blur () {
blur (e) {
this.isMenuActive = false
this.isFocused = false
this.$refs.input && this.$refs.input.blur()
this.selectedIndex = -1
this.onBlur(e)
},
/** @public */
activateMenu () {
Expand Down Expand Up @@ -646,7 +647,7 @@ export default {
// If we make it here,
// the user has no selected indexes
// and is probably tabbing out
VTextField.methods.onBlur.call(this, e)
this.blur(e)
}
},
selectItem (item) {
Expand Down
24 changes: 24 additions & 0 deletions packages/vuetify/test/unit/components/VSelect/VSelect3.spec.js
Expand Up @@ -194,4 +194,28 @@ test('VSelect', ({ mount, compileToFunctions }) => {
expect(menu.nudgeBottom).toBe(5)
expect(menu.nudgeLeft).toBe(5)
})

// https://github.com/vuetifyjs/vuetify/issues/5774
it('should close menu on tab down when no selectedIndex', async () => {
const wrapper = mount(VSelect, {
propsData: {
items: ['foo', 'bar']
}
})

const menu = wrapper.first('.v-input__slot')
const input = wrapper.first('input')

menu.trigger('click')

expect(wrapper.vm.isFocused).toBe(true)
expect(wrapper.vm.isMenuActive).toBe(true)

input.trigger('keydown.tab')

await wrapper.vm.$nextTick()

expect(wrapper.vm.isFocused).toBe(false)
expect(wrapper.vm.isMenuActive).toBe(false)
})
})

0 comments on commit 8a2a1a1

Please sign in to comment.