I am using the library micromodal.js to handle the functionality of my (accessible) modal dialogs.
Having read recommendations about a11y best practices, I have learned that the modal should get a tabindex="-1"
in order to "trap" the tabbing user (or screen reader) in the modal dialog.
One of the modals I am using it for has scrollable content section. In order to facilitate the content to be focusable and therefore scrollable by arrow keys, I added tabindex="0"
to the section.
On mobile devices it is not the content that should be scrollable, but the whole modal.
The issue that this solution creates is: when opening the modal on smaller screens, the content is focussed first (due to tabindex of 0 being larger than tabindex of -1, I guess?) and the whole header of the modal is not visible.
The desired behavior is that the modal header is visible when it opens. How could I achieve that with still providing an accessible UX?
Code example: https://codepen.io/AstiV/pen/vYKopNZ