Skip to content

Commit

Permalink
fixup! fix(NcSelect): stop propagation of ESC on closing select
Browse files Browse the repository at this point in the history
  • Loading branch information
ShGKme committed Sep 7, 2023
1 parent 45c28b5 commit 4c7ebb4
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/components/NcSelect/NcSelect.vue
Expand Up @@ -480,7 +480,6 @@ export default {
:class="{
'select--no-wrap': noWrap,
}"
:map-keydown="patchedKeydownHandler"
v-bind="propsToForward"
v-on="$listeners"
@search="searchString => search = searchString">
Expand Down Expand Up @@ -769,6 +768,39 @@ export default {
default: '',
},
/**
* Customized component's response to keydown events while the search input has focus
*
* @see https://vue-select.org/guide/keydown.html#mapkeydown
*/
mapKeydown: {
type: Function,
/**
* Patched Vue-Select keydown events handlers map to stop Escape propagation in open select
*
* @param {Record<number, Function>} map - Mapped keyCode to handlers { <keyCode>:<callback> }
* @param {import('@nextcloud/vue-select').VueSelect} vm - VueSelect instance
* @return {Record<number, Function>} patched keydown event handlers
*/
default(map, vm) {
return {
...map,
/**
* Patched Escape handler to stop propagation from open select
*
* @param {KeyboardEvent} event - default keydown event handler
*/
27: (event) => {
if (vm.open) {
event.stopPropagation()
}
// Default VueSelect's handler
map[27](event)
},
}
},
},
/**
* When `appendToBody` is true, this sets the placement of the dropdown
*
Expand Down Expand Up @@ -945,34 +977,6 @@ export default {
return propsToForward
},
},
methods: {
/**
* Patch Vue-Select keydown event handlers to stop Escape propagation in open select
*
* @see https://vue-select.org/guide/keydown.html#mapkeydown
* @param {Record<number, Function>} map - Mapped keyCode to handlers { <keyCode>:<callback> }
* @param {import('vue-select').VueSelect} vm - VueSelect instance
* @return {Record<number, Function>} patched keydown event handlers
*/
patchedKeydownHandler(map, vm) {
return {
...map,
/**
* Patched Escape handler to stop propagation from open select
*
* @param {KeyboardEvent} event - default keydown event handler
*/
27: (event) => {
if (vm.open) {
event.stopPropagation()
}
// Default VueSelect's handler
map[27](event)
},
}
},
},
}
</script>

Expand Down

0 comments on commit 4c7ebb4

Please sign in to comment.