diff --git a/LICENSE b/LICENSE index d7120e5..a45a04d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Simon Osterlehner +Copyright (c) 2023 Simon Osterlehner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8d28983..4c335d2 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ With `:propagate="true"` the event will be passed to the parent listeners as wel ```html @@ -89,11 +89,11 @@ With `:propagate="true"` the event will be passed to the parent listeners as wel ##### Enable or Disable the hotkey -When the hotkey should not be usable, it can easily be disabled by setting `:enabled="false"`. +When the hotkey should not be usable, it can easily be disabled by setting `disabled`. ```html @@ -116,6 +116,18 @@ It will prevent the hotkey when the currently focused HTML element is of the spe ``` +##### Key check + +Only call a function when the hotkey is pressed. Can be used for special on-click actions based on a hotkey. + +```html + +``` + ### Use as a hook When there is no specific element tied to the hotkey, it can be used as a hook with `useHotkey()`: @@ -166,3 +178,17 @@ useHotkey( ["radio", "div"] ); ``` + +##### Key check function + +The excluded elements can be specified with the hook as well. The default is again `input` and `textarea`. + +```ts +const { keyCheckFn } = useHotkey({ ... }); + +const doSomething = keyCheckFn((name: string, count: number) => { + // do anything when the hotkey is pressed when doSomething is called +}) + +doSomething("myProps", 123); +``` diff --git a/package.json b/package.json index 83151d1..d945d70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@simolation/vue-hotkey", - "version": "1.1.10", + "version": "2.0.0", "repository": "https://github.com/Simolation/vue-hotkey.git", "author": "Simon Osterlehner ", "license": "MIT", diff --git a/src/components/HotKey.vue b/src/components/HotKey.vue index 359be92..3aa46f7 100644 --- a/src/components/HotKey.vue +++ b/src/components/HotKey.vue @@ -94,7 +94,7 @@ export default defineComponent({ props.excludedElements ); - const keyCheck = keyCheckFn((action: (...params: any[]) => any) => + const keyCheck = keyCheckFn((action: (...params: any[]) => any | void) => action() );