Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
accessible-modal-dialog
Advanced tools
A tiny script to make modal dialogs accessible to assistive technology users.
This repository is a fork from accessible-modal-dialog by Greg Kraus. We at Edenspiekermann are big fans of the original version, although we discovered we could improve it and make it even better. On top of that, the original script depends on jQuery, which happened to be a problem for us.
The original repository being apparently unmaintained, we decided to fork it and release our own version of the accessible modal dialog. All credits to the original author.
You can try the live demo.
data-modal-show="modal-id"
) and closers (data-modal-hide
);modal.show()
, modal.hide()
);modal.shown
);[tabindex]:not([value="-1"])
to focusable elements;You will find a concrete demo in the example folder of this repository, but basically here is the gist:
// Get the modal element (with the accessor method you want)
var modalEl = document.getElementById('my-awesome-modal');
// Instanciate a new Modal module
var modal = new Modal(modalEl);
The script assumes the main document of the page has a main
id, and the overlay element has a modal-overlay
id. If it is not the case, you can pass these two nodes respectively as second and third arguments to the Modal
constructor:
var modal = new Modal(modalEl, mainEl, overlayEl);
There are 2 ways of toggling the modal. Either through the DOM API, or directly with JavaScript. Both ways are inter-operable so feel free to use both if you need it.
The following button will open the modal with the my-awesome-modal
id when interacted with.
<button type="button" data-modal-show="my-awesome-modal">Open the modal</button>
The following button will close the modal in which it lives when interacted with.
<button type="button" data-modal-hide title="Close the modal">×</button>
The following button will close the modal with the my-awesome-modal
id when interacted with. Given that the only focusable elements when the modal is open are the focusable children of the modal itself, it seems rather unlikely that you will ever need this but in case you do, well you can.
<button type="button" data-modal-hide="my-awesome-modal" title="Close the modal">×</button>
Regarding the JS API, it simply consists on show()
and hide()
methods on the modal instance.
// Show the modal
modal.show();
// Hide the modal
modal.hide();
The example page is deployed through GitHub Pages.
npm run example
FAQs
A tiny script to make modal dialogs accessible to assistive technology users.
The npm package accessible-modal-dialog receives a total of 4 weekly downloads. As such, accessible-modal-dialog popularity was classified as not popular.
We found that accessible-modal-dialog demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.