Skip to content

[BUG] Key released still pressed if the focus is lost #307

@ds4biz

Description

@ds4biz

Describe the bug
If I press a key that open for example a dialog (that makes the Hotkeys component wrapper to lose focus) when the dialog is closed the key pressed for open it is still pressed when I try to use other mapped hotkeys.
This is a basic reproduction: CODESANDBOX

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc)
HotKeys

Expected behavior
When the component lose focus keys pressed should be reset or refreshed, and at least a method to do it manually

Platform (please complete the following information):

  • Version of react-hotkeys: 2.0.0
  • Browser [e.g. chrome, safari] Chrome
  • OS: [e.g. iOS] MacOs

Are you willing and able to create a PR request to fix this issue?
I don't think

Include the smallest log that includes your issue:

HotKeys (F1📗-E5🧡-C1⭐️-P0🔺:) New 'Delete' keydown event.
HotKeys (F1📗-E5🧡-C0🔺) Found action that matches 'Delete': DELETE. Calling handler . . .
HotKeys (F1📗-E5🧡-C0🔺) Stopping further event propagation.
HotKeys (F1📗-E7💚-C1⭐️-P0🔺:) New (simulated) 'Delete' keypress event.
HotKeys (F1📗-C1⭐️-P0🔺:) Received new props.
HotKeys (F1📗-C1⭐️-P0🔺:) Lost focus.    -----> THIS HAPPENS WHEN DIALOG OPENS
HotKeys (F2📘-C1⭐️-P0🔺:) Focused.       -----> THIS HAPPENS WHEN I CLOSE DIALOG
HotKeys (F2📘-E8💙-C1⭐️-P0🔺:) New 'Escape' keydown event
HotKeys (F2📘-E8💙-C0🔺) No matching actions found for 'Delete+Escape' keydown.     -----> I JUST PRESS "DELETE"
HotKeys (F2📘-E10💜-C1⭐️-P0🔺:) New (simulated) 'Escape' keypress event.
HotKeys (F2📘-E11🧡-C1⭐️-P0🔺:) New 'Escape' keyup event.
HotKeys (F2📘-E11🧡-C0🔺) No matching actions found for 'Delete+Escape' keyup.     -----> WRONG KEYS COMBO TRIGGERED (DELETE IS NOT STILL PRESSED)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions