Convert Figma logo to code with AI

ghosh logoMicromodal

⭕ Tiny javascript library for creating accessible modal dialogs

3,526
229
3,526
67

Top Related Projects

1,553

⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use

2,718

An accessible dialog window library for all humans.

2,759

No longer actively maintained.

✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦

Quick Overview

Micromodal is a lightweight, accessible, and customizable modal library written in pure JavaScript. It allows developers to create modal dialogs that are keyboard-friendly and follow WAI-ARIA guidelines for accessibility. The library is designed to be easy to use and integrate into existing projects.

Pros

  • Lightweight and dependency-free, with a small file size
  • Fully accessible, following WAI-ARIA guidelines
  • Customizable with various configuration options
  • Easy to integrate with existing projects

Cons

  • Limited built-in styling options, requiring custom CSS for advanced designs
  • No built-in support for nested modals
  • May require additional work to make it compatible with older browsers

Code Examples

  1. Basic usage:
MicroModal.init();

// Open modal
MicroModal.show('modal-1');

// Close modal
MicroModal.close('modal-1');
  1. Custom configuration:
MicroModal.init({
  openTrigger: 'data-custom-open',
  closeTrigger: 'data-custom-close',
  disableScroll: true,
  awaitCloseAnimation: true,
  onShow: modal => console.log(`${modal.id} is shown`),
  onClose: modal => console.log(`${modal.id} is hidden`)
});
  1. Programmatically control modals:
const modal = document.getElementById('modal-1');

// Open modal
MicroModal.show('modal-1', {
  onShow: modal => console.log(`${modal.id} is shown`)
});

// Close modal
MicroModal.close('modal-1', {
  onClose: modal => console.log(`${modal.id} is hidden`)
});

Getting Started

  1. Install Micromodal:
npm install micromodal --save
  1. Import and initialize in your JavaScript file:
import MicroModal from 'micromodal';

MicroModal.init();
  1. Add HTML markup for your modal:
<div id="modal-1" aria-hidden="true">
  <div tabindex="-1" data-micromodal-close>
    <div role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
      <header>
        <h2 id="modal-1-title">Modal Title</h2>
        <button aria-label="Close modal" data-micromodal-close></button>
      </header>
      <div id="modal-1-content">
        Modal content goes here
      </div>
    </div>
  </div>
</div>
  1. Trigger the modal:
<button data-micromodal-trigger="modal-1">Open Modal</button>

Competitor Comparisons

1,553

⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use

Pros of Tingle

  • More customizable with additional options for positioning, transitions, and callbacks
  • Supports multiple instances on a single page
  • Includes built-in CSS styles for quicker implementation

Cons of Tingle

  • Larger file size (11.5KB vs 3.5KB for Micromodal)
  • Less focus on accessibility features
  • Requires more setup code for basic functionality

Code Comparison

Tingle:

var modal = new tingle.modal({
    footer: true,
    stickyFooter: false,
    closeMethods: ['overlay', 'button', 'escape'],
    closeLabel: "Close",
    cssClass: ['custom-class-1', 'custom-class-2'],
});
modal.setContent('<h1>Here\'s some content</h1>');
modal.open();

Micromodal:

MicroModal.init();
MicroModal.show('modal-1');

Both libraries offer lightweight solutions for creating modal dialogs, but they cater to different needs. Tingle provides more out-of-the-box features and customization options, making it suitable for complex use cases. Micromodal, on the other hand, focuses on simplicity and accessibility, with a smaller footprint and easier implementation for basic modal functionality. The choice between the two depends on the specific requirements of your project, balancing features against file size and ease of use.

2,718

An accessible dialog window library for all humans.

Pros of Modaal

  • More customizable appearance with built-in themes and styling options
  • Supports image galleries and iframes out of the box
  • Includes accessibility features like ARIA attributes and keyboard navigation

Cons of Modaal

  • Larger file size (around 23KB minified) compared to Micromodal's lightweight approach
  • Requires jQuery as a dependency
  • Less focus on performance optimization

Code Comparison

Micromodal:

MicroModal.show('modal-id');

Modaal:

$('.modal-trigger').modaal({
  type: 'inline',
  content_source: '#modal-content'
});

Summary

Modaal offers more built-in features and customization options, making it suitable for projects requiring complex modal functionality. However, it comes at the cost of a larger file size and jQuery dependency. Micromodal, on the other hand, focuses on simplicity and performance, with a smaller footprint and no dependencies. The choice between the two depends on project requirements, with Modaal being better for feature-rich modals and Micromodal for lightweight, performant implementations.

2,759

No longer actively maintained.

Pros of Remodal

  • More customizable with various animation options and styles
  • Supports multiple instances on a single page
  • Includes built-in close button functionality

Cons of Remodal

  • Larger file size and potentially heavier performance impact
  • Less focus on accessibility features
  • Requires jQuery as a dependency

Code Comparison

Remodal:

$(document).on('opening', '.remodal', function () {
  console.log('Modal is opening');
});

$('[data-remodal-id=modal]').remodal();

Micromodal:

MicroModal.init({
  onShow: modal => console.log(`${modal.id} is shown`)
});

MicroModal.show('modal-1');

Key Differences

  • Remodal uses jQuery syntax and relies on the library, while Micromodal is vanilla JavaScript
  • Micromodal has a more straightforward API with a focus on simplicity
  • Remodal offers more built-in customization options, but Micromodal provides better accessibility out of the box
  • Micromodal has a smaller footprint and potentially better performance, especially for simpler use cases
  • Remodal may be easier to implement for developers already familiar with jQuery, while Micromodal aligns better with modern JavaScript practices

✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦

Pros of SweetAlert2

  • More feature-rich with a wide range of customization options
  • Larger community and more frequent updates
  • Built-in themes and animations

Cons of SweetAlert2

  • Larger file size, which may impact page load times
  • More complex API, potentially steeper learning curve
  • Dependency on CSS for styling

Code Comparison

SweetAlert2:

Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonText: 'Yes, delete it!'
})

Micromodal:

MicroModal.show('modal-1', {
  onShow: modal => console.info(`${modal.id} is shown`),
  onClose: modal => console.info(`${modal.id} is hidden`),
  openTrigger: 'data-custom-open',
  closeTrigger: 'data-custom-close'
});

SweetAlert2 offers a more declarative approach with built-in options for common use cases, while Micromodal provides a simpler API focused on modal functionality. SweetAlert2 is better suited for complex alert scenarios, whereas Micromodal excels in lightweight, customizable modal implementations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Micromodal.js

Made with love License Package version Build Status

Tiny, dependency-free javascript library for creating accessible modal dialogs


The aim of this library is to make modal dialogs accessible and easy to include in your project with minimum configuration. It's only ~1.8kb minified and gzipped - A tiny library for big change.

Demo and documentation

 

Features

✔ Toggles relevant aria attributes on open and close

✔ Closes modal on overlay click

✔ Closes modal on pressing the esc key

✔ Traps tab focus within the modal

✔ Focuses on the first focusable element within the modal

✔ Retains the focused element state after closing the modal

 

Installation

via npm

npm install micromodal --save

via yarn

yarn add micromodal

via CDN direct link

<script src="https://cdn.jsdelivr.net/npm/micromodal/dist/micromodal.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/micromodal/dist/micromodal.min.js"></script>

direct download

curl -O -L https://unpkg.com/micromodal/dist/micromodal.min.js

 

IE 11 and below

Please use this pollyfill suggested here.

 

Changelog

Find the latest changelog here.

 

Contributing

We are always open and invite developers to contribute to Micromodal. We have kept the guidelines and process dead simple, so you invest more time in making modals accessible to all.

Micromodal follows the standardjs coding standard and is part of our package.json file. It will help us to maintain consistency in the code base.

Development setup

  1. Clone Github repo $ git clone https://github.com/ghosh/micromodal.git
  2. Install yarn package manager (Read installation guide)
  3. Run yarn install in the root folder to install all dependencies
  4. Run yarn dev to start a dev server. This serves the example directory and live reloads when any files are changed
  5. [Optional] Run yarn build to build the files for distribution. This is run automatically as a pre-commit hook as well.
  6. Send us pull request and chill

 

Licensing

This project is licensed under MIT license.

 

Related

  • Microtip - Modern, lightweight, accessible css tooltip library. Just 1kb.

 

Contact

You can mention us on Twitter for any questions, suggestions or just send us funny GIF. We ♥️ GIFs.

Tweet some love

Tweet about Micromodal and help us to spread the message about the importance of Web accessibility and Inclusive design.

 

Created and maintained by

Indrashish Ghosh – @_ighosh 🇮🇳

Kalpesh Singh - @knowkalpesh 🇮🇳

Darpan Kakadia - @kakadiadarpan 🇩🇪

Contributors - list 🌐

NPM DownloadsLast 30 Days