Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
aria-modal
Advanced tools
Accessible modal with Web Components
aria-modal that is a fully accessible is built according to WAI-ARIA Authoring Practices. And it provide the only simple features. It makes be easy to implement accessible modal. If you use polyfill, you can use @webcomponents/webcomponentsjs.
https://keiya01.github.io/aria-modal-doc/top/
Using npm:
$ npm install aria-modal
import 'aria-modal';
/**
* do something
*/
You can append your modal inside aria-modal with slot
. If you use slot
, you can use accessible feature for modal.
Please see following example.
<aria-modal
app="app"
first-focus="button"
animation="true"
active="active"
>
<div id="node" slot="modal" role="dialog" aria-labelledby="title">
<!-- ... -->
<button id="button"></button>
</div>
</aria-modal>
If you use custom element, see the following code.
<aria-modal
app="app"
active="active"
animation="true"
>
<!--
<simple-modal> must be contained `firstFocus` function that return HTMLElement.
And You must set role and aria-* attributes to your modal.
-->
<simple-modal slot="modal"></simple-modal>
</aria-modal>
Using css variables, you can apply your style to <aria-modal>
.
aria-modal {
--backdrop-display: block; /* or flex, inline-block, etc... */
--backdrop-color: rgba(0, 0, 0, 0.3); /* background-color for backdrop */
--backdrop-position: fixed; /* or fixed */
--backdrop-z-index: none;
--animation-function: linear;
--animation-duration: 300ms;
/* required, if fade property is false */
--animation-delay: none;
}
If you want to set your modal to center, you can use margin: auto;
and flexbox
property.
aria-modal {
--backdrop-display: flex;
/* ... */
}
.your-modal {
margin: auto;
height: 300px;
width: 500px;
background-color: #fff;
}
Required: false
, Type: boolean
, Default: false
It is used to show modal. You can set true
if you want to open modal.
Required: true
, Type: string
or function firstFocus(): HTMLElement
It is used to focus to first element when modal is opened. You should assign id
name.
If first-focus
element is a custom element or inside a custom element, You must implement firstFocus
method to your slotted element. That is, slotted element must be custom element if first-focus
element is custom element.
class SampleModal extends HTMLElement {
get template() {
const template = document.createElement('template');
template.innerHTML = `
<div>
<button id="first-element">Button</button>
</div>
`;
}
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
shadowRoot.appendChild(this.template.content.cloneNode(true));
}
/**
* Do something
*/
// You must implement `firstFocus()`, if you use custom element.
firstFocus() {
return this.shadowRoot.getElementById('first-element');
}
}
Required: true
, Type: string
It is used to set aria-hidden
to your app
element. You should set main contents id
name.
Notice: Don't contain aria-modal
inside main contents. If you contain aria-modal
to your main contents, screen readers can not find aria-modal
.
Required: false
, Type: boolean
, Default: false
If true
, you can use animation. aria-modal run fade animation by default.
If you want to use custom animation, you can use active
and hide
properties.
Required: false
, Type: boolean
, Default: true
If false
, default fade animation is disabled.
Required: false
, Type: string
active
is class name that is added when open
props is changed to true
.
Required: false
, Type: string
hide
is class name that is added when open
props is changed to false
.
Required: false
, Type: boolean
If true, disable clicking on the backdrop.
Required: true
, Type: string
You must include aria-label
or aria-labelledby
property to your modal.
See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute
Required: false
, Type: string
Required: true
, Type: string
You must include role
property to your modal.
Assignable value is dialog
or alertdialog
. See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles
Required: false
, Type: boolean
, Default: false
This property is some problems, see this article https://developer.paciellogroup.com/blog/2018/06/the-current-state-of-modal-dialog-accessibility/
And if you want to know about aria-modal
, see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/dialog_role
If the active class is not set to aria-modal
, it may flicker when reloaded on browser. When you set active class, you should set your modal to display: none;
and you should set your active class to display: block; /* or flex, inline-block, etc... */
.
This problem is occurred by rendering process for Web Components. Your modal is assigned to slot
element in aria-modal
, and slot
is rendered after JavaScript file(and Web Components) have loaded. That is, this problem is occurred by your modal is rendered without your modal is assigned to slot.
https://github.com/keiya01/aria-modal/tree/master/example
FAQs
Accessible modal with Web Components
The npm package aria-modal receives a total of 53 weekly downloads. As such, aria-modal popularity was classified as not popular.
We found that aria-modal 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.