2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-07 07:12:23 +03:00
Files
vue-select/docs/guide/keydown.md
T
Jeff Sagal 223f3a6d85 Squashed commit of the following:
commit 8c3a1b107b
Author: Jeff Sagal <sagalbot@gmail.com>
Date:   Fri Jul 15 09:57:37 2022 -0700

    bump to vitepress 1.0.0-alpha.4

commit 96ff08406c
Author: Jeff Sagal <sagalbot@gmail.com>
Date:   Wed Feb 23 10:25:36 2022 -0800

    vitepress wip

    mostly working, feeling like vuepress should still be considered

commit f3e22e0439
Author: Jeff Sagal <sagalbot@gmail.com>
Date:   Sat Feb 19 17:18:30 2022 -0800

    remove yarn, rename readme

commit 8cd3bbeb51
Author: Jeff Sagal <sagalbot@gmail.com>
Date:   Sat Feb 19 17:17:22 2022 -0800

    install vitepress
2022-07-18 09:40:42 -07:00

74 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### Customizing Keydown Behaviour
---
## selectOnKeyCodes <Badge text="v3.3.0+" />
`selectOnKeyCodes {Array}` is an array of keyCodes that will trigger a typeAheadSelect. Any keyCodes
in this array will prevent the default event action and trigger a typeahead select. By default,
it's just `[13]` for return. For example, maybe you want to tag on a comma keystroke:
<TagOnComma />
<<< @/.vitepress/components/TagOnComma.vue
## mapKeyDown <Badge text="v3.3.0+" />
Vue Select provides the `map-keydown` Function prop to allow for customizing the components response to
keydown events while the search input has focus.
```js
/**
* @param map {Object} Mapped keyCode to handlers { <keyCode>:<callback> }
* @param vm {VueSelect}
* @return {Object}
*/
(map, vm) => map,
```
By default, the prop is a noop returning the same object `map` object it receives. This object
maps keyCodes to handlers: `{ <keyCode>: <callback> }`. Modifying this object can override default
functionality, or add handlers for different keys that the component doesn't normally listen for.
Note that any keyCodes you've added to `selectOnKeyCodes` will be passed to `map-keydown` as well,
so `map-keydown` will always take precedence.
**Default Handlers**
```js
// delete
8: e => this.maybeDeleteValue()
// tab
9: e => this.onTab()
// enter
13: e => {
e.preventDefault();
return this.typeAheadSelect();
}
// esc
27: e => this.onEscape()
// up
38: e => {
e.preventDefault();
return this.typeAheadUp();
}
// down
40: e => {
e.preventDefault();
return this.typeAheadDown();
}
```
### Example: Autocomplete Email Addresses
This is example listens for the `@` key, and autocompletes an email address with `@gmail.com`.
<CustomHandlers />
<<< @/.vitepress/components/CustomHandlers.vue