4.0.0-1 #788
JohannesKlauss
announced in
Announcements
4.0.0-1
#788
Replies: 1 comment 2 replies
-
this type is not exported and correct type for 2nd argument in callback cant be used |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The first pre release of version 4!
Note that there are a lot of breaking changes, so it will be unlikely that your app won't need any updating.
🚨 Breaking Changes
filter
merges intoenabled
enabled
takes aTrigger
. A trigger can either be a boolean or a a function that return a boolean to determine if the option should trigger. The function gets the keyboardEvent and the hotkeysEvent which you can use to determine if the hotkey should be enabled or not.splitKey
is now calledcombinationKey
(still defaults to+
)splitKey
now refers to the separation of keystrokes (defaults to,
)DependencyList
instead ofany[]
cmd
andcommand
hotkeys are not longer available. Usemeta
instead.enableOnTags
has been renamed toenableOnFormTags
➕ Features
useHotkeys
Arguments
options
object and the dependency array are swappable. This means that you can calluseHotkeys
in multiple ways:useHotkeys('ctrl+a', () => console.log('pressed'))
useHotkeys('ctrl+a', () => console.log('pressed'), options)
useHotkeys('ctrl+a', () => console.log('pressed'), [dependencyA, dependencyB])
useHotkeys('ctrl+a', () => console.log('pressed'), options, [dependencyA, dependencyB])
useHotkeys('ctrl+a', () => console.log('pressed'), [dependencyA, dependencyB], options)
(possible, but not recommended, might be dropped for release)useHotkeys(['ctrl+a', 'shift+b'], () => console.log('pressed'))
Scopes
<HotkeysProvider>
component. Scopes are toggled by using theuseHotkeysContext()
hook. It returns the following functions:activateScope: (scope: string) => void
- Activates given scope, i.e.activateScope('settings')
deactivateScope: (scope: string) => void
- Deactivates given scope, i.e.deactivateScope('settings')
toggleScope: (scope: string) => void
- Toggles a given scope, i.e.toggleScope('settings')
activeScopes: string[]
- Returns an array with all active scopes (defaults to['*']
for wildcard)hotkeys: Hotkey[]
- Returns an array of all currently bound hotkeys*
which matches all hotkeys no matter their scope(s).scopes
option in the options object:useHotkeys('a', () => console.log('I am in scope settings'), {scopes: 'settings'})
. This hotkey will only be active, when the "settings" scope is activated.Options
enabled
takes aTrigger
. A trigger can either be a boolean or a a function that return a boolean to determine if the option should trigger. The function gets the keyboardEvent and the hotkeysEvent which you can use to determine if the hotkey should be enabled or not. Default istrue
.preventDefault
take aTrigger
to determine if the browsers default behavior should be prevented (callinge.preventDefault()
internally if Trigger resolves totrue
). Defaults tofalse
.enableOnTags
now also accepts a boolean. If set totrue
, all form Tags will be enabled (defaults tofalse
)➕ Features
isHotkeyPressed
isHotkeyPressed('a')
|isHotkeyPressed(['a', 'b'])
|isHotkeyPressed('a, b')
splitKey
string to split between hotkeys (only works if first argument is a string):isHotkeyPressed('a+,', '+')
This discussion was created from the release 4.0.0-1.
Beta Was this translation helpful? Give feedback.
All reactions