mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 07:31:26 +00:00
Allow array of keycombos in useKeydown
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup({closeModal}){
|
setup({closeModal}){
|
||||||
useKeydown({key: 'Escape', fn: closeModal})
|
useKeydown([{key: 'Escape', fn: closeModal}])
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
closeModal: {
|
closeModal: {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { onBeforeUnmount } from 'vue';
|
import { onBeforeUnmount } from 'vue';
|
||||||
|
|
||||||
export const useKeydown = function(keyCombo) {
|
export const useKeydown = function(keyCombos) {
|
||||||
let onkey = function(event) {
|
let onkey = function(event) {
|
||||||
if(keyCombo.key == event.key) {
|
let kc = keyCombos.find(({key, fn}) => key == event.key )
|
||||||
keyCombo.fn()
|
if(kc) {
|
||||||
|
kc.fn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user