Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add closing of the icon details modal with the ESC key #900

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

gabrielogregorio
Copy link
Contributor

@gabrielogregorio gabrielogregorio commented Jan 11, 2024

Description:

Added the useKeyDown hook to improve interaction with the site using the keyboard, this specific pull request I am using this hook to close the icon details modal by pressing the ESC key.

The hook listens to the global window "keydown" event and triggers a callback function with a key pressed.

Example of closing the modal using the ESC key

simplescreenrecorder-2024-01-11_19.57.13.mp4

The hook synchronizes the ref with the most current value of the callback function, without interrupting the listener.

const refCallback = useRef(callback);

useEffect(() => {
    refCallback.current = callback;
}, [call back]);

Benefits:

With this it will be possible to use the ESC keys to close the icon detail modal, I personally find it much more practical.

References:

  • This behavior is used for example in headless ui library
  • In github in the search bar, to exit it
  • In Youtube, sidebar, notifications, etc.

And on other sites.

I'm open to suggestions

@gabrielogregorio gabrielogregorio marked this pull request as ready for review January 11, 2024 22:45
@gabrielogregorio gabrielogregorio changed the title Add closing of the icon details modal with the ESC key Feat: Add closing of the icon details modal with the ESC key Jan 11, 2024
@gabrielogregorio gabrielogregorio changed the title Feat: Add closing of the icon details modal with the ESC key Add closing of the icon details modal with the ESC key Jan 11, 2024
@kamijin-fanta kamijin-fanta added the preview-site(low priority) About preview web site label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview-site(low priority) About preview web site
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants