Duder-onomy / svelte-focus-trap

Svelte directive that will trap focus within itself. Useful for modals or other places you want focus to trap and wrap.
MIT License
30 stars 2 forks source link

svelte-focus-trap

npm

A svelte directive that will trap focus within an element. You can navigate child focusable elements with up, down, tab, shift + tab, alt + tab. I have attempted to match the accesibility best practices listed here.

This could be useful if you wanted to trap focus within something like a modal. When you gotta... focus-trap and focus-wrap.

Todos:

Installation

npm install --save-dev svelte-focus-trap

Usage

<script>
  import { focusTrap } from 'svelte-focus-trap'
</script>

{#if showing}
  <div
    use:focusTrap
  > 
    <!-- ...modal contents -->
  </div>
{/if}

License

This project is licensed under the MIT License.