A very lightweight and flexible accessible modal dialog script.

Overview

A11y Dialog

This is a lightweight (1.3Kb) yet flexible script to create accessible dialog windows.

Features:

  • Closing dialog on overlay click and ESC
  • Toggling aria-* attributes
  • Trapping and restoring focus
  • Firing events
  • DOM and JS APIs
  • Fast and tiny

Contributing

Contributing guidelines can be found in CONTRIBUTING.md

Comments
  • Main ID for unknown html markup

    Main ID for unknown html markup

    Thanks for great accessible modal dialog script. I've been looking something like this for a while.

    I understand perfectly why there is id="main" or passing the ID as a second parameter. However when I wanted to use this script in public WordPress Plugin where I can only take educated guess about ID names. In other words I don't know html markup.

    I guess my question is that would second parameter also be false if I have no clue about the markup?

    opened by samikeijonen 38
  • Find a better global name

    Find a better global name

    Edit: A11yDialog has been chosen. Please check https://github.com/edenspiekermann/accessible-modal-dialog/issues/22#issuecomment-187626418 to give your opinion!

    Modal seems a bit too generic for a global variable. It would be a good idea to find a better name. However it will be a breaking change (v2).

    Ideas:

    • AccessibleModalDialog (a bit long?)
    • AMD (probably not a good idea)
    • ESPIDialog (not a fan of branding everything)
    • AMDialog
    • A11yDialog
    • Any other suggestion?
    opened by KittyGiraudel 19
  • Make all events go through the DOM

    Make all events go through the DOM

    This is a proof of concept that would make all events go through the DOM under the hood. This would mean they would no longer be attached to the dialog instance itself, but on the dialog DOM container instead. This just reduces the amount of code shipped (not by a lot though).

    ~The way this is implemented would likely cause no API breaking change.~ The object passed to the events would now be a CustomEvent, and accessing the underlying DOM node would require reading event.detail.currentTarget instead of event.currentTarget, so this is a breaking change.

    We could also decide to drop .on and .off methods entirely, but it might be good to keep them for convenience. Otherwise the API would be a little awkward (having to read the element from the instance to bind listeners).

    opened by KittyGiraudel 16
  • Disable tabbing on modal content when hidden

    Disable tabbing on modal content when hidden

    I know that the recommendation is to have this css:

    [aria-hidden="true"] {
      display: none;
    }
    

    However that solution leaves much to be desired in terms of in-out transitions using CSS.

    Since the modal code already implements the ability to disable focus on elements, as used on the modals siblings, would it be possible to do the same thing for the modal content when closing the modal?

    This would enable the ability to use other means of hiding the visual side of the dialog when closing it, which includes transitions in and out.

    opened by Munter 16
  • Order of the close button in source

    Order of the close button in source

    This is not an issue per se but I wonder about the position of the "close" button in the markup. I believe sighted keyboard users would expect to reach the button after tabbing out of the heading—since that's the visual flow.

    What about having 2 buttons? One after the heading and one last in the dialog? With the same styling/positioning of course. Does that make sense?

    opened by thierryk 15
  • Performance issue due to focus state in Safari

    Performance issue due to focus state in Safari

    Not so much of an issue that needs fixing but it might be useful to mention in the docs:

    While implementing a11y-dialog in a website I ran into a strange issue due to Safari’s user agent stylesheet. This is a fullscreen dialog, the dialog content spans the whole screen. As soon as the dialog opens focus is set on the dialog container. Safari applies user agent styles for the focus which then hinder the performance. For instance resizing the browser becomes very choppy. Also when you’ve applied animations to the dialog these don’t run and skip to the end immediately as Safari is struggling. The solution I’ve used to resolve this is to set .container:focus { outline: none}.

    opened by iksi 14
  • Event.detail contains element which triggered the event

    Event.detail contains element which triggered the event

    Hi,

    thanks for great modal dialog plugin.

    I used it in my project where I use one dialog instance to display details about team members. Information is in the markup, so I needed to detect which team member modal dialog is open to inser proper data. For this reason I did modify the script so event detail property contains element which actually triggered show or hide event.

    I believe this could be useful to others as well so I would like to merge it with your repo, if you are interest.

    opened by Pustelto 13
  • Add support for role='alertdialog'.

    Add support for role='alertdialog'.

    First time contributor. Posting for feedback before jumping into tests, docs and examples. Hopefully its a small, non-breaking change.

    Adds support for role='alertdialog', making the dialog modal by not closing it when the escape key is pressed. Note that the data-a11y-dialog-hide attribute should be removed from the overlay as well to comply with the specification.

    Closes #83.

    opened by flu0 12
  • Uncaught RangeError in Blink and WebKit browsers

    Uncaught RangeError in Blink and WebKit browsers

    I have a setup where I open a modal and then want to step from the currently open modal to the next one. From the second modal I want to go to either the previous modal, or the next one, and so on.

    The pseudo-code of the buttons inside the modal that enable this behavior:

    Modal 1

    <button data-a11y-dialog-hide="modal-1" data-a11y-dialog-show="dialog-2" >next modal</button>
    

    Modal 2

    <button data-a11y-dialog-hide="dialog-2" data-a11y-dialog-show="dialog-1">prev modal</button>
    <button data-a11y-dialog-hide="dialog-2" data-a11y-dialog-show="dialog-3" >next modal</button>
    

    … and so on.

    Now, when I click on the "next" button in the first modal, everything works as expected, the modal 1 hides and modal 2 shows up. In fact, the "next" button of all modals works just fine.

    But when I click on the "prev" button e.g. in the second modal, to go back to the first modal, I get the following error in Chrome, Opera, and Safari (aka. Blink and WebKit browsers):

    Uncaught RangeError: Maximum call stack size exceeded.
    

    Test scenario: http://jsbin.com/bumimohexi/1/edit?html,js,output

    What is causing this and how can I avoid it?

    opened by isellsoap 11
  • It remove aria-hidden attribute for hidden element on dialog closing

    It remove aria-hidden attribute for hidden element on dialog closing

    When we open a dialog, it put aria-hidden attribute to true for each element of document other than dialog itself.

    And when we close the dialog box, aria-hidden attribute is removed to each of them.

    But when an element is aria-hidden="true" yet before opening, a11y-dialog remove the attribute at closing, but it shouldn't.

    opened by ryuran 10
  • Make showing / hiding cancellable via event listeners

    Make showing / hiding cancellable via event listeners

    Use case: I want to display a form in the dialog. When the user accidentally clicks outside the dialog or on the close button, the dialog closes without warning. I could check in the hide event listener if the user has already entered some data and confirm if they really want to close.

    It would be great if I then could just return false in the event listener to cancel the action. Maybe a beforeHide event would also be valuable.

    The same can also be applied to the show event, though I guess it won't be too helpful.

    opened by FloEdelmann 9
  • Handle shadow children when trapping focus

    Handle shadow children when trapping focus

    Summary

    This overhaul of getFocusableChildren replaces querySelectorAll with a manual, recursive DOM traversal. This traversal is necessary because there's no way to query into shadow subtrees.

    I have ideas for tests, as well, but I will follow up with them in a separate PR to keep this one small.

    Huge thanks to the inimitable @alice for listening to me complain about Shadow DOM and helping me figure this algorithm out.

    Relevant issues

    This, ideally, closes #322.

    opened by mxmason 0
  • Close button doesn't work when added after modal shown

    Close button doesn't work when added after modal shown

    We have a workflow where we fetch the modal content from the server when the modal trigger is clicked. We want to give the user some feedback, so we show the modal backdrop with a loader and then dynamically add the modal content when the response comes back from the server. What I'm noticing, though, is that the modal close doesn't work with this workflow. It appears that event handlers are registered on any existing "hide" elements when the modal is first shown, but if the close icon is added after the modal is shown then it doesn't work.

    We can work around this on our end by tracking clicks to the close button ourselves, but I wonder if there is an event delegation based approach that might work in a11y-dialog in order to support elements being added later.

    Improvement 
    opened by mockdeep 4
  • History api support for closing and opening modal

    History api support for closing and opening modal

    Would it be possible for this library to get history api support, like one described there? https://github.com/jamesnuanez/history-api-with-modals-demo

    I think it would be especially useful on mobile devices where users are used to closing modals with back button.

    I played around a little with implementing it using a11y dialog events but didn't sucedeed.

    Feature 
    opened by piotrpog 6
  • [Discussion] New chance for <dialog>?

    [Discussion] New chance for ?

    opened by masi 5
  • Focus trapping fails to account for elements within shadow DOM

    Focus trapping fails to account for elements within shadow DOM

    We are building a web component that uses a11y-dialog—this is similar to the framework implementations of the library but for web components.

    We've noticed that focusable elements within shadow DOM are not picked up by the logic in _maintainFocus. This is because event.target.closest is not able to see into shadow DOM.

    I'm wondering if you're open to a PR (and/or collaboration) that would upgrade this logic with shadow DOM support so this library can work properly with web components.

    Thanks in advance!

    Bug 
    opened by elidupuis 6
Releases(7.5.2)
  • 7.5.2(Aug 17, 2022)

    What's Changed

    • Fix incorrect handling of nested dialogs (#399, #400)
    • Remove obsolete styles from the fixture files (754d56cc8f2886e5a1dba1d984dc93f52508ef9f)
    • Update focusable-selectors dependency (c61526e1dd4468006807c7dc4609534f5ac5c604)
    • Update dev dependencies (c22e463e0f6f0ed938ed781e6317d765707a455e)

    Full Changelog: https://github.com/KittyGiraudel/a11y-dialog/compare/7.5.1...7.5.2

    Source code(tar.gz)
    Source code(zip)
  • 7.5.1(Aug 5, 2022)

    What's Changed

    • Add missing type for ‘shown’ property by @KittyGiraudel in https://github.com/KittyGiraudel/a11y-dialog/pull/394

    Full Changelog: https://github.com/KittyGiraudel/a11y-dialog/compare/7.5.0...7.5.1

    Source code(tar.gz)
    Source code(zip)
  • 7.5.0(Jun 9, 2022)

    What's Changed

    • Upgrade Cypress to v10 in https://github.com/KittyGiraudel/a11y-dialog/pull/359
    • Update event.which to event.key by @tomasvn in https://github.com/KittyGiraudel/a11y-dialog/pull/357
    • Bump a lot of dependencies via Dependabot

    New Contributors

    • @tomasvn made their first contribution in https://github.com/KittyGiraudel/a11y-dialog/pull/357

    Full Changelog: https://github.com/KittyGiraudel/a11y-dialog/compare/7.4.0...7.5.0

    Source code(tar.gz)
    Source code(zip)
  • 7.4.0(Mar 25, 2022)

    What's Changed

    • Add prefers-reduced-motion for cypress fixtures by @roblevintennis in https://github.com/KittyGiraudel/a11y-dialog/pull/254
    • Adds contributing and links from top-level README.md by @roblevintennis in https://github.com/KittyGiraudel/a11y-dialog/pull/257
    • Enable hide and show functions to accept CustomEvent by @ZerdoX-x in https://github.com/KittyGiraudel/a11y-dialog/pull/326
    • Bump a lot of dependencies via Dependabot

    New Contributors

    • @ZerdoX-x made their first contribution in https://github.com/KittyGiraudel/a11y-dialog/pull/326

    Full Changelog: https://github.com/KittyGiraudel/a11y-dialog/compare/7.3.0...7.3.1

    Source code(tar.gz)
    Source code(zip)
  • 7.3.0(Sep 2, 2021)

    • Dispatch DOM events alongside custom ones so the lifecycle events can be reacted to for auto-instantiated dialogs as well (#237, #238)
    • Update dev dependencies (#229, #230, #231, #232, #233, #234, #235, #236)
    Source code(tar.gz)
    Source code(zip)
  • 7.2.0(Aug 7, 2021)

    • Focus the dialog container instead of its first focusable element on dialog open (#228)
    • Update focusable-selectors (f661846a9d8f475e07ab6e824ceaab4fe4f376cd)
    • Apply Rollup cosmetic change to ESM exports (22f7f57fddb87c647fa00da1bc0f261e07137e4a)
    Source code(tar.gz)
    Source code(zip)
  • 7.1.0(Mar 29, 2021)

  • 7.0.3(Mar 25, 2021)

  • 7.0.2(Mar 25, 2021)

  • 6.1.1(Mar 25, 2021)

  • 7.0.1(Mar 23, 2021)

  • 7.0.0(Mar 23, 2021)

    Version 7 of a11y-dialog aims at reducing complexity, both in terms of implementation, but also in terms of usage.

    It is not backward compatible with version 6 (hence the major version bump). The update should not be overly difficult, but requires development work. Read the migration guide.

    • [Breaking] Drop support for the native <dialog> element (and the open HTML attribute). It is inconsistent, and already actively discouraged in the documentation. There is a lot of logic around supporting its side-effects which we would be better off. (#158, #163)

    • [Breaking] Use aria-modal="true" to no longer make the main content container(s) inert with aria-hidden="true". This significantly reduces the markup expectations and limit the risks of passing the incorrect main content container(s) to the library since it no longer needs them. (#155, #164)

    As a result, using a11y-dialog should become significantly easier, and the script size dropped ~20% (now around 1.3Kb).

    Source code(tar.gz)
    Source code(zip)
  • 7.0.0-rc.1(Mar 6, 2021)

    Version 7 of a11y-dialog aims at reducing complexity, both in terms of implementation, but also in terms of usage.

    It is not backward compatible with version 6 (hence the major version bump). The update should not be overly difficult, but requires development work. Read the migration guide.

    • [Breaking] Drop support for the native <dialog> element (and the open HTML attribute). It is inconsistent, and already actively discouraged in the documentation. There is a lot of logic around supporting its side-effects which we would be better off. (#158, #163)

    • [Breaking] Use aria-modal="true" to no longer make the main content container(s) inert with aria-hidden="true". This significantly reduces the markup expectations and limit the risks of passing the incorrect main content container(s) to the library since it no longer needs them. (#155, #164)

    As a result, using a11y-dialog should become significantly easier, and the script size dropped ~20% (now around 1.3Kb).

    Source code(tar.gz)
    Source code(zip)
  • 6.1.0(Mar 2, 2021)

    • Fix minor issues when querying focusable elements (#156)
    • Improve instructions regarding CDN usage (#154)
    • Add documentation about locking window scroll (#153)
    • Simplify a JavaScript expression (2cc152fd7fd365f0ac06b8f995eddcf3879f3650)
    • Update author’s name (e94c7d4)
    • Move documentation to Docusaurus (tree/documentation, #161, 1813b7737838922cb6ed86c3a8e69e194e29aeda, ab4c7956c84b2b4ef5113d9b2378ae2ecf623249, 04de7f3c3baf0593f93a988f2cb466381ef3f54b)
    • Move example to CodeSandbox (cc22140ab9ea8bbcfc223e0469b554f893cc27ef, 580a284c5c37e71433b4abbad704ae50cdc428e5, c05e45e39772a1f6aa00c9a7b1f8d46f814a4128)
    Source code(tar.gz)
    Source code(zip)
  • 6.0.1(Feb 22, 2021)

  • 6.0.0(Feb 17, 2021)

    In theory, v6.0.0 should be entirely backward compatible with the latest version from v5. However since the move to Rollup could have unintended side-effect, we’re leaning on the safe side and bumping the major. If you are experiencing any issue with v6, please kindly report them.

    Package

    • Add support for nested dialogs (#141)
    • Move bundling to Rollup (#133)
    • Use focusable-selectors to get focusable elements (#134, #143)
    • Package an ESM version of the script for CDN usage (#133)
    • Move dist files in a dedicated folder, leaving only the source file at the root (#133)
    • Move the repository over to KittyGiraudel/a11y-dialog instead of edenspiekermann/a11y-dialog (#138)

    Documentation

    • Improve the documentation about the expected HTML structure (#137)
    • Add a warning about using <dialog> in the documentation (#137)
    • Update installation instructions to mention ESM and CDNs (#139, #140)

    Tests

    • Move testing from Mocha to Cypress (#129)
    • Run tests on CI (#130)
    • Clean up examples (#142)
    Source code(tar.gz)
    Source code(zip)
  • 5.5.2(Feb 15, 2021)

  • 5.5.1(Feb 14, 2021)

    • Prevent a DOM error when ‘data-a11y-dialog’ has no value (30a8c2f51244d84866eb43099f2c673aece353fa)
    • Apply minor improvement to the documentation (b3f6856ecd3ca58c87390da5f08c37f9443bf185)
    Source code(tar.gz)
    Source code(zip)
  • 5.5.0(Feb 14, 2021)

    • Provide a way to automatically instantiate dialogs through the DOM API to make it possible to use the library without writing any JavaScript (#128)
    Source code(tar.gz)
    Source code(zip)
  • 5.4.3(Feb 6, 2021)

    • Update development dependencies (a1e21de663225324cc99139e69f8779136527694, ec13ef5f679ad69c28b26f2623ad1709ed4789a8, 7c1ce973774f242ab51ace7f20ce3be99a4fad90, 6b1e50ac1ebfaa6515ca7684d4d4f26e82eb900d, 3b5ccb20a7190473a90c701e4b64dbb624be6a07)
    • Rename master to main (9718f2a479620a74d4e42930fcd3ab25eaee445b)
    • Update author’s name (e0d398032ebb56b43cc1401e3b144fc3d6082439)
    Source code(tar.gz)
    Source code(zip)
  • 5.4.2(Oct 26, 2020)

  • 5.4.1(Oct 11, 2020)

  • 5.4.0(Oct 9, 2020)

  • 5.3.2(Jun 16, 2020)

  • 5.3.1(Mar 13, 2020)

  • 5.3.0(Mar 7, 2020)

  • 5.2.0(Sep 17, 2018)

  • 5.1.2(Jun 28, 2018)

  • 5.1.1(Jun 18, 2018)

  • 5.1.0(Jun 15, 2018)

Owner
Kitty Giraudel
Non-binary accessibility & diversity advocate, frontend developer, author. Real life cat. They/them.
Kitty Giraudel
react-dialog is a custom react hook to use a dialog easily

react-dialog react-dialog is a custom react hook to use a dialog easily. Documentation To use react-dialog follow the documentation. useDialog Returns

Levy Mateus Macedo 2 Mar 29, 2022
This is an online dialog with realtime chat, voice and face to face.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Gökhan ERGEN 2 Jun 7, 2022
Makes the HTML element dialog draggable

Makes the HTML element dialog draggable

Naeemo 2 Sep 9, 2022
Modal in desktop, fullscreen in mobile

React Full Screen Modal Why? Modals typically don't work well for modals. They take up a lot of space and often squish their contents. This library ai

Chris 2 Mar 7, 2022
Material-UI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

Material-UI Quickly build beautiful React apps. Material-UI is a simple and customizable component library to build faster, beautiful, and more access

Material-UI 83.6k Dec 30, 2022
Beautiful and accessible drag and drop for lists with React

react-beautiful-dnd (rbd) Beautiful and accessible drag and drop for lists with React Play with this example if you want! Core characteristics Beautif

Atlassian 28.9k Jan 7, 2023
A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list Examples available here: http://claude

Claudéric Demers 10.3k Jan 2, 2023
Accessible, unstyled, open-sourced, and fully functional react component library for building design systems

DORAI UI Accessible, unstyled, open-sourced and fully functional react component library for building design systems Documentation site coming soon St

Fakorede Boluwatife 38 Dec 30, 2022
⚡️ Simple, Modular & Accessible UI Components for your React Applications

Build Accessible React Apps with Speed ⚡️ Chakra UI provides a set of accessible, reusable, and composable React components that make it super easy to

Chakra UI 30.5k Jan 4, 2023
An accessible dropdown component for use in Ember apps.

ember-a11y-dropdown This is an accessible dropdown that you can use in your Ember app for a menu dropdown. I'm making it so people can stop using the

Melanie Sumner 2 Feb 10, 2022
Providing accessible components with Web Components & Material You

tiny-material Still on developing, DO NOT use for production environment Run well on Google Chrome, Firefox, Chrome for Android, Microsoft Edge (Chrom

HugePancake 11 Dec 31, 2022
A declarative, efficient, and flexible JavaScript library for building user interfaces.

React · React is a JavaScript library for building user interfaces. Declarative: React makes it painless to create interactive UIs. Design simple view

Facebook 200.2k Jan 8, 2023
🌊 A flexible and fun JavaScript file upload library

A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user

pqina 13.1k Dec 31, 2022
🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.

downshift ?? Primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components. Read the docs | See

Downshift 11.1k Dec 28, 2022
Gnome Shell extension to provide a flexible applications dock (WIP).

Flexi Dock (WIP) Gnome Shell extension to provide a flexible applications dock. Installation The easiest way to install this extension is via the offi

Hardpixel 3 Aug 29, 2022
Provide solutions to make your app flexible for different screen sizes, different devices.

react-native-size-scaling Provide solutions to make your app flexible for different screen sizes, different devices, based on your device's pixel rati

Hoà Phan 33 Dec 23, 2022
Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand.

About Plock ?? Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand. Can I see a demo? ?? The demo

Renato Pozzi 130 Dec 9, 2022
Very simple app to decode your Vaccination Proof QR Code (such as the one provided by government of Quebec) - Compatible with SHC (Smart Health Card standard)

shc-covid19-decoder Visit simple hosted version on your phone (does NOT transmit any data, all remains in your browser) https://fproulx.github.io/shc-

François Proulx 148 Sep 23, 2022
🐥 A very simple way to transform antd table to xlsx

antd-table-2-xlsx antd-table-2-xlsx A very simple way to transform antd table to xlsx . Get Start! Install pnpm add @sudongyuer/antd-table-2-xlsx Usa

Frozen FIsh 18 Aug 15, 2022