nico3333fr / jquery-accessible-modal-window-aria

jQuery simple and accessible modal window, using ARIA
MIT License
60 stars 20 forks source link
a11y accessibility aria jquery modal

jQuery Simple and Accessible Modal Window

This jQuery plugin provides you a shiny and accessible modal window, using ARIA.

A presentation page and demo is here: https://a11y.nicolas-hoffmann.net/modal/ (with styles, etc.)

How it works

Basically, it wraps all the page into a div id="js-modal-page", and when you activate one modal, the scripts inserts a dialog element at the end of your page, adds the noscroll class on the body element (to remove scroll with CSS if needed), puts the focus into it and traps focus in the modal window. When you exit it, the focus is given back to the element that opened it.

For mouse users, they can click outside the modal window to close it. For keyboard users, you can strike Esc to close it.

If you never activate a modal window, it won’t be anywhere in the code.

Options and attributes

Simply put class="js-modal" on a button or a link to activate the script.

If you need to close it, add class="js-modal-close" on an element in the modal content, it will trigger a click on close button.

Enjoy.

Chuck Norris approved this

P.S: this plugin is in MIT license. It couldn't be done without the precious help of @ScreenFeedFr, @sophieschuermans, @johan_ramon, @goetsu and @romaingervois.