Skip to content

hchiam/keyboard-focus-trap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keyboard focus trap (especially useful for modals)

version License: MIT HitCount

Live demo

Example usage

<script
  src="https://cdn.jsdelivr.net/gh/hchiam/[email protected]/keyboard-focus-trap.js"
  integrity="sha384-X4CXOjFm0n6iwt8qEFOvwsXLyZonS799Q47YRuZPFQOTUHXkGlV9kXsbjpZ1S3rm"
  crossorigin="anonymous"
></script>
bash get-integrity.sh

Inspirations for this

Caveat/gotcha

https://stackoverflow.com/questions/44452084/how-to-keep-focus-within-modal-dialog/44481275#44481275

May not work well with web components and shadow DOM, but can be overcome with custom code.