Skip to content

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
@kamijin-fanta
Copy link
Member

Thank you for contributing! This is very user-friendly.

auto-merge was automatically disabled August 13, 2024 11:11

Head branch was pushed to by a user without write access

@gabrielogregorio gabrielogregorio force-pushed the feat-accessibility-improvements-esc-menu branch from 7855c2f to 0216900 Compare August 13, 2024 11:17
@gabrielogregorio
Copy link
Contributor Author

I fixed the most prettier formatting, it had been forgotten

@gabrielogregorio gabrielogregorio force-pushed the feat-accessibility-improvements-esc-menu branch 3 times, most recently from 5382af8 to 97de7b8 Compare August 13, 2024 11:43
@gabrielogregorio gabrielogregorio force-pushed the feat-accessibility-improvements-esc-menu branch from 97de7b8 to 2ad9c87 Compare August 13, 2024 11:44
@kamijin-fanta kamijin-fanta added this pull request to the merge queue Aug 13, 2024
Merged via the queue into react-icons:master with commit 183a9a1 Aug 13, 2024
1 check passed
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.

2 participants