Feature Request
Summary
Currently, the enabled option in HotkeyOptions only accepts a boolean. It would be useful to also accept a callback (i.e. () => boolean) to support lazy evaluation.
Motivation
There are cases where the enabled state depends on values that are re-evaluated at hotkey trigger time, not at registration time. Having to re-register the hotkey every time that condition changes is cumbersome.
A callback form would allow users to defer the check to when the hotkey is actually fired:
useHotkeys('mod+s', save, {
enabled: () => !isReadOnly,
})
Proposed API change
// Current
enabled?: boolean
// Proposed
enabled?: boolean | (() => boolean)
The implementation would just call enabled() instead of reading it directly when it's a function.
Alternatives considered
Passing a reactive enabled value that changes over time works, but requires the caller to manage that reactivity and causes unnecessary re-registrations.
Feature Request
Summary
Currently, the
enabledoption inHotkeyOptionsonly accepts aboolean. It would be useful to also accept a callback (i.e.() => boolean) to support lazy evaluation.Motivation
There are cases where the enabled state depends on values that are re-evaluated at hotkey trigger time, not at registration time. Having to re-register the hotkey every time that condition changes is cumbersome.
A callback form would allow users to defer the check to when the hotkey is actually fired:
Proposed API change
The implementation would just call
enabled()instead of reading it directly when it's a function.Alternatives considered
Passing a reactive
enabledvalue that changes over time works, but requires the caller to manage that reactivity and causes unnecessary re-registrations.