Closed theetrain closed 1 year ago
Thanks for taking action, though there were some regressions:
It was likely caused by these lines that calls event.preventDefault()
on all key actions:
Maybe you can short-circuit the onKeyDown
method when
if (event.key !== 'Tab' && event.key !== 'Escape') return
A potential enhancement for later could be a parameter to opt-in to top-level modal placement (since we cannot make assumptions for where the user places their modal); that way you can leverage the inert
attribute to disable other direct descendants of <body>
as a means of having focus trapping:
<script lang="ts">
import { createDialog } from 'svelte-headlessui'
const dialog = createDialog({ label: 'Payment Success', topLevel: true })
</script>
<main inert>
<!-- main user content -->
</main>
<div /> <!-- modal goes here -->
Ha, I forgot the bit that needs to actually test it's the tab key being pressed! (and ignore if not)
Hopefully that fixes it for now and I'll look more into the inert / topLevel option you suggested.
Nice work with these svelte actions. 🕶️
For the Dialog, please consider these accessibility features:
aria-modal="true"
to opened dialogrole="dialog"
to opened dialogReference: https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/dialog