-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
With only react-kbs it is not possible to setup an alternative mode as long as a key is pressed.
We have to hook directly on addEventListener, ex:
useKbsGlobal([
{
shortcut: 'Shift',
handler: () => {
actions.setMode('select');
function resetMode(event: KeyboardEvent) {
if (event.key !== 'Shift') return;
actions.setMode('rotate_selected');
document.body.removeEventListener('keyup', resetMode);
}
document.body.addEventListener('keyup', resetMode);
},
},
]);Inspired from useEffect with cleanup function returned by the handler, we could support a cleanup method returned by the shortcut handler:
useKbsGlobal([
{
shortcut: 'Shift',
handler: () => {
actions.setMode('select');
return () => actions.setMode('rotate_selected');
},
},
]);Or we can add onKeyUp option:
useKbsGlobal([
{
shortcut: 'Shift',
handler: () => {
actions.setMode('select');
},
onKeyUp: () => {
actions.setMode('rotate_selected');
},
},
]);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request