
A trap focus function you need for your modals - vaskort
https://vaskort.com/the-only-trap-focus-function-you-will-need/
======
Etheryte
Focus traps are great and a crucial part of making a site with modals
accessible, and I also think reimplementing things from scratch can be a great
way to learn about them. However I'd caution anyone against using
accessibility scripts written from scratch. Accessibility is notoriously hard
to get right and there's numerous nontrivial details that need to be nailed
down.

> The code is pretty W3’s example, just a bit simplified and explained.

The problem here being that W3's solution is cross-browser compatible and you
can reasonably expect it to work on screen readers of all sorts. The code in
the post won't even work correctly on all modern browsers.

I wouldn't be saying all this otherwise, as again, rewriting things is great
for learning them. However the title of the post, "The only trap focus
function you need for your modals", can mislead your readers into a false
sense of security.

~~~
vaskort
Thanks for the comment Etheryte :)

