New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

modal-utility

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modal-utility

A set of functions that allow creating accessible modals.

  • 1.0.0-alpha.6
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
3
Weekly downloads
 
Created
Source

Modal Utility

This module provides Javascript and Sass to enable creating modal windows. General UI Events are provided by default (see parameters section) in relation to the modals:

  • When a user presses the Esc key, the modal will be removed, and the focus returned to where it came from.
  • When a user clicks the modal-mask (anywhere outside the modal), the modal will be removed and focus is returned to where it came from.
  • When a modal is shown, its given focus.
  • When a user tries to Tab out of a modal, focus returns to the modal.

Getting Started

npm install modal-utility

You only need to import these two files into your build:

dist/_modal-utility.scss
dist/modal-utility.js

The Javascript is an ES6 module

Once its imported, you'll need to execute a setup function like so:

const modalUtility = ModalUtility(document);

Then you can use a set of functions returned, like so:

config options

const options = {
    title: 'This is my title',
    dismissable: true
};

create some content

const modalContents = document.createElement('p');
modalContents.textContent = 'Hello, Modal';

create a modal

let modal = modalUtility.createModal(document, options);

set the content into the modal

modalUtility.setContents(modal, modalContents);

show the modal

modalUtility.showModal(document, modal);

hide the modal

modalUtility.hideModal(document);

Optional Settings

SettingDescription
titleThe text to display in the title area of the modal
dismissableTrue if the modal removal events should be bound, False if not. (default: true)
additionalClassesAn array of classes to set on the modal
headingClassesAn array of classes to set on the heading

Parameters for the createModal function

ParameterPurpose
optionsAn object containing various settings, see below

Parameters for the setContents function

ParameterPurpose
modala modal created with ModalUtility, contents will be inserted into its content area
contentsa DOM Element containing 0 or more other Elements to be inserted

Parameters for the showModal function

ParameterPurpose
modala modal created with ModalUtility, appended to the given element

Notes

  • When the viewport is very narrow or shallow, the modal will attach to the top of the viewport.
  • hideModal will hide all modals created with ModalUtility.

Contribution

  • Fork, open a PR

FAQs

Package last updated on 21 Jul 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc