MoodleJS
An accessible modal that follows the WebAim standards.
Features
- Uses a keyboard trap when user has selected open modal
- When you get to the last focusable element it will go back to the first
- When you
shift + tab
and you're on the first focusable element you will go to the last - Uses
aria-labelledby
&aria-describedby
for title and text fields. - Sets focus on first focuable element when opened.
- Resets focus on the previous element when closing the modal.
Usage
This is the basic example for having multiple products working with one modal.
Hello World Hello World Heading. Product One Product one detail Product Two Product Two detail Close
CSS
Here is just the baseline to having the modal sit infront of the content & the overlay to sit behind.
JS
To create the modal all the have to do is use the new Moodle();
and the modal will handle the rest. For example:
{ var modal = ; var buttons = document; { event; var currentElement = eventcurrentTarget; var heading = currentElement0textContent; var detail = currentElement0textContent; var html = ''; modal; } buttons1; buttons2;};
Using with webpack
If you are using the module with webpack or some other bundler then you can do the following:
npm i moodlejs --save
Then in your js file you will have to require the module.
{ var modal = ; // Products example var buttons = document; { event; var currentElement = eventcurrentTarget; var heading = currentElement0textContent; var detail = currentElement0textContent; var html = ''; modal;} buttons1;buttons2;};
Contributing
Feel free to suggest any ideas or improvments to the plugin. If you have any issues using it feel free to submit an issue.