Skip to content

Commit

Permalink
feat(VSelect): add update:listIndex event to VSelect
Browse files Browse the repository at this point in the history
update:listIndex added to VSelect to indicate when keyboard-selected item is changed
  • Loading branch information
mateuszgachowski committed Jul 15, 2019
1 parent 2578f23 commit 62a4957
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/api-generator/src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ const VSelect = {
name: 'update:searchInput',
value: 'string',
},
{
name: 'update:listIndex',
value: 'number',
},
...inputEvents,
...textEvents,
].concat(validatableEvents),
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/lang/en/components/Autocompletes.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"click:prepend": "Components.Inputs.events['click:prepend']",
"click:prepend-inner": "Components.TextFields.events['click:prepend-inner']",
"update:error": "Mixins.Validatable.events['update:error']",
"update:menuListIndex": "Emitted when menu item is selected using keyboard arrows",
"update:listIndex": "Emitted when menu item is selected using keyboard arrows",
"update:searchInput": "The `search-input.sync` event"
}
}
1 change: 1 addition & 0 deletions packages/docs/src/lang/en/components/Selects.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"click:prepend": "Components.Inputs.events['click:prepend']",
"click:prepend-inner": "Components.TextFields.events['click:prepend-inner']",
"update:error": "Mixins.Validatable.events['update:error']",
"update:listIndex": "Emitted when menu item is selected using keyboard arrows",
"update:searchInput": "The `search-input.sync` event"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,24 @@ describe('VAutocomplete.ts', () => {

expect(wrapper.vm.genSelections()).toEqual([])
})

it('should emit listIndex event when navigated by keyboard', () => {
const wrapper = mountFunction({
propsData: {
items: ['foo', 'bar'],
},
})

const listIndexUpdate = jest.fn()
wrapper.vm.$on('update:listIndex', listIndexUpdate)

const input = wrapper.find('input')
const slot = wrapper.find('.v-input__slot')
slot.trigger('click')

input.trigger('keydown.down')
expect(listIndexUpdate).toBeCalledWith(0)
input.trigger('keydown.down')
expect(listIndexUpdate).toBeCalledWith(1)
})
})
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VSelect/VSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ export default baseMixins.extend<options>().extend({
// listIndex change from menu
if (this.isMenuActive && keyCode !== keyCodes.tab) {
menu.changeListIndex(e)
this.$emit('update:listIndex', menu.listIndex)
}

// If menu is not active, up and down can do
Expand Down

0 comments on commit 62a4957

Please sign in to comment.