New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@curiousmedia/modal-accessibility

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curiousmedia/modal-accessibility

Accessibility enhancements for modals

latest
npmnpm
Version
2.0.2
Version published
Maintainers
5
Created
Source

Modal Accessiblity

Accessibility enhancements for modals

  • Sets focus to modal on open
  • Return focus on modal close
  • ESC closes modal
  • Isolates focus to modal when tabbing through elements

Example

CSS

    .modal {
        display: none;
        position: fixed;
        top: 20px;
        width: 400px;
        height: 300px;
        background-color: #EFEFEF;
        left: 50%;
        transform: translate(-50%, 0);
    }

    .modal[data-open="1"] {
        display: block;
    }

HTML

<button class="toggle">Toggle</button>
<div class="modal" aria-modal="true">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
</div>

Javascript

class Modal {
    constructor(modal) {
        this._open = false;
        this.modal = modal;
        this.accessibility = new ModalAccessibility(this.modal, () => {
            this.open = false;
        });

        document.querySelector('.toggle').addEventListener('click', (e) => {
            e.preventDefault();

            this.open = !this.open;
        });
    }

    get open() {
        return this._open;
    }

    set open(value) {
        this._open = value;

        if(value) {
            this.modal.setAttribute('data-open', 1)
            this.accessibility.open();
        } else {
            this.modal.setAttribute('data-open', 0)
            this.accessibility.close();
        }
    }
}

new Modal(document.querySelector('.modal'));

FAQs

Package last updated on 04 Jun 2021

Did you know?

Socket

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.

Install

Related posts