humaan / Modaal

An accessible dialog window library for all humans.
http://humaan.com/modaal/
MIT License
2.72k stars 183 forks source link

Modal content outside ARIA landmark #140

Open peterh-capella opened 2 years ago

peterh-capella commented 2 years ago

The default behavior of injecting the div.modaal-wrapper at the end of the body has the side-effect of removing the content therein from any ARIA landmarks defined on the page. This limits the ability of assistive technologies to navigate to the content and also causes failures in automated accessibility checks.

I suggest checking for the presence of one of the tags with an implicit ARIA landmark role as parent of the modal content and inserting the div.modaal-wrapper element at the end of that element, falling back to current behavior if such an element is not present.

I'm willing to work on developing this update if it seems valuable to the project.

danhumaan commented 2 years ago

hi @peterh-capella thanks for raising the issue. This version of Modaal is no longer being worked, with a new non-jquery dependant version being planned.

Rather than you invest time in applying it to this version, if you're able to share the steps you've used to identify and test the issue, we can apply that approach to the new version when it's further along

peterh-capella commented 2 years ago

The issue came up for me due to my firm's use of the Siteimprove service (https://siteimprove.com/). Their recent updates to their testing engine flagged many instances of a best-practice issue, "Text not included in an ARIA landmark." This would show up for applications that included an introductory modal describing the academic activity the user was starting. We have standard pattern of opening that modal on page load which then injects the HTML structure at the end of the <body>. This removes the content from the <main> landmark, leaving it outside of any landmark and thus failing the test. You can see this on the Modaal demo page by opening one of the examples and the using their Chrome extension.

My plan to remediate this was to look into where the script built the div.modaal-wrapper and associated HTML structure and prior to that see if the content defined either by the trigger's href or content_source existed inside one of the elements with implicit ARIA landmark roles (<header>, <footer>, <main>, <nav>, <aside>, <form> or <section>). Then build the existing HTML structure inside that element. Complications I see arising from this are the styling of the modal position based on the parent.

Another option would be to use a <section> as the outer wrapper of the modal structure. That would require giving the region an accessible name, most likely through an aria-label attribute, which presents complications of naming and localization.

I hope that's useful. If I can assist with the new version let me know.