Mithril modal component: focus not trapped and screen reader announces nothing on open
0 reputation · 27 May 2021, 10:58 UTC
I am building a modal dialog as a Mithril component and trying to make it behave correctly for keyboard and screen-reader users. My understanding is that Mithril renders vnodes to plain HTML without injecting ARIA roles, labels, or live regions, and that the framework ships no focus-trapping or focus-return utilities, so everything must be declared in the vnode attrs and handled in lifecycle methods such as oncreate and onupdate.
The goal is a dialog that, when opened, receives role="dialog" with an accessible name, moves focus into the modal, keeps Tab and Shift+Tab cycling inside it, closes on Escape, and returns focus to the triggering element on close. I am unsure which parts belong in attrs versus lifecycle hooks, and whether focus restoration needs to survive redraws triggered by m.route or state changes while the modal is open.
Assume Mithril 2.x. I plan to verify with an axe-core audit, manual keyboard walkthrough, and DOM inspection after m.mount.
Is there a documented or community-accepted pattern for focus trapping in Mithril lifecycle methods? Should aria-modal and focus management be re-asserted on every onupdate, or only oncreate? Are there known pitfalls where a redraw drops focus out of the dialog?