[Code Demo] Focus Trapping in Modal System | JSer - Front-End Interview questions

Опубликовано: 29 Сентябрь 2024
на канале: JSer
3,398
49

In previous video:    • [Code Demo] create Modal System with ...   we've created a modal system in React with context API.
One problem of accessibility is Focus Trapping, in this code demo, we managed to handle 4 requirements below
1. when modal is opened, focus the first focusable element
2. TAB/SHIFT + TAB should be within the modal
3. ESC to close the modal
4. when closed, refocus the trigger

Here is my code, hope it helps https://codesandbox.io/s/xenodochial-...

Hi I'm a JavaScript engineer who is not good at algorithms,
and currently practicing leetCode & BFE.dev. If you are interested, maybe we can learn together.