Description
Summary
When using a modal in a Preline + SvelteKit + TailwindCSS project set up as instructed by documentation, modal tab order is incorrect.
Steps to Reproduce
- Create new Sveltekit + Tailwind project per https://tailwindcss.com/docs/guides/sveltekit
- Install Preline with SvelteKit configurations per https://preline.co/docs/frameworks-svelte.html
- Install overlay and forms
- Create basic modal per https://preline.co/docs/modal.html
- Create basic input per https://preline.co/docs/input.html (with or without tabindex="0")
The example has been provided with focusable elements, however taborder is incorrect even without them.
If there are no focusable elements in the modal, then tab will only move to the Close button, with no ability to tab to the Close icon.
I believe the problem has something to do with these lines from preline.js:
onTab:
e.onTab = function(t, e) { if (!e.length) return !1; var n = t.element.overlay.querySelector(":focus") , o = Array.from(e).indexOf(n); o > -1 ? e[(o + 1) % e.length].focus() : e[0].focus() }
autoInit:
(e.autoInit = function () { window.$hsOverlayCollection || (window.$hsOverlayCollection = []), document .querySelectorAll('[data-hs-overlay]:not(.--prevent-on-load-init)') .forEach(function (t) { window.$hsOverlayCollection.find(function (e) { var n; return ( (null === (n = null == e ? void 0 : e.element) || void 0 === n ? void 0 : n.el) === t ); }) || new e(t); }), window.$hsOverlayCollection && document.addEventListener('keydown', function (t) { return e.accessibility(t); }); }),
In my tests, this function runs successfully initially for the element with the :focus pseudo-class and the correct index is returned, however, the document keydown event is initiated three times:
- From preline itself
- From the 'goto' event from afterNavigate
afterNavigate((result)=>console.log(result.type)
- From the 'enter' event from afterNavigate
afterNavigate((result)=>console.log(result.type)
Removing the call to window.HSStaticMethods.autoInit();
in afterNavigate results in modals not working, and a call to either breaks the tab order again, so I haven't been able to develop a good workaround (short of removing all focusable elements in a modal besides the action buttons, which isn't an acceptable solution).
Please let me know if there is any other info I can provide to help nail this down!
Demo Link
https://stackblitz.com/~/github.com/fortserious/sveltekit-preline-modal-accessibility-bug
Expected Behavior
Tabbing through inputs proceeds in DOM order: Close (Icon), Input 1, Input 2, Close, Save Changes.
Actual Behavior
Tabbing through inputs proceeds in unusual order: Input 2, Close (Icon), Close (button), Input 1, Save Changes.
Screenshots
No response