Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle tab in autoselect #354

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/pages/documentation/form/autocomplete/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default [
props: [
{
name: '<code>v-model</code>',
description: 'Bindig value',
description: 'Binding value',
type: 'String, Number',
values: '—',
default: '—'
Expand Down Expand Up @@ -31,7 +31,7 @@ export default [
},
{
name: '<code>keep-first</code>',
description: 'The first option will always be pre-selected (easier to just hit enter)',
description: 'The first option will always be pre-selected (easier to just hit enter or tab)',
type: 'Boolean',
values: '—',
default: '<code>false</code>'
Expand Down
14 changes: 14 additions & 0 deletions src/components/autocomplete/Autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@focus="focused"
@blur="$emit('blur', $event)"
@keyup.native.esc.prevent="isActive = false"
@keydown.native.tab="tabPressed"
@keydown.native.enter.prevent="enterPressed"
@keydown.native.up.prevent="keyArrows('up')"
@keydown.native.down.prevent="keyArrows('down')">
Expand Down Expand Up @@ -212,6 +213,19 @@
this.setSelected(this.hovered)
},

/**
* Tab key listener.
* Select hovered option if it exists, close dropdown, then allow
* native handling to move to next tabbable element.
*/
tabPressed() {
if (this.hovered === null) {
this.isActive = false
return
}
this.setSelected(this.hovered)
},

/**
* Close dropdown if clicked outside.
*/
Expand Down