Convert Figma logo to code with AI

KittyGiraudel logoa11y-dialog

A very lightweight and flexible accessible modal dialog script.

2,423
130
2,423
7

Top Related Projects

A boilerplate for Sass projects using the 7-1 architecture pattern from Sass Guidelines.

Quick Overview

The KittyGiraudel/a11y-dialog repository provides a lightweight, accessible, and customizable dialog/modal component for the web. It aims to improve the user experience and accessibility of dialog interactions on websites and web applications.

Pros

  • Accessibility-Focused: The library is designed with accessibility in mind, ensuring that the dialog component adheres to WCAG (Web Content Accessibility Guidelines) standards.
  • Lightweight and Customizable: The library is small in size and provides a range of customization options, allowing developers to tailor the dialog to their specific needs.
  • Cross-Browser Compatibility: The library is compatible with a wide range of modern browsers, ensuring a consistent user experience across different platforms.
  • Dependency-Free: The library does not require any external dependencies, making it easy to integrate into existing projects.

Cons

  • Limited Functionality: While the library provides a basic dialog/modal functionality, it may lack some advanced features that some developers might require.
  • Lack of Animations: The library does not include built-in animations for the dialog, which some users might expect or prefer.
  • Minimal Documentation: The project's documentation could be more comprehensive, making it slightly more challenging for new users to get started.
  • Infrequent Updates: The project has not been actively maintained in the last few years, which could be a concern for some users who prefer regularly updated libraries.

Code Examples

Here are a few examples of how to use the a11y-dialog library:

  1. Initializing the Dialog:
import a11yDialog from 'a11y-dialog';

const dialog = new a11yDialog(document.getElementById('my-dialog'));
  1. Opening the Dialog:
document.getElementById('open-dialog').addEventListener('click', () => {
  dialog.show();
});
  1. Closing the Dialog:
document.getElementById('close-dialog').addEventListener('click', () => {
  dialog.hide();
});
  1. Customizing the Dialog:
const dialog = new a11yDialog(document.getElementById('my-dialog'), {
  onShow: () => console.log('Dialog shown'),
  onHide: () => console.log('Dialog hidden'),
  closeButtonLabel: 'Close',
  trapFocus: true,
  disableScroll: true
});

Getting Started

To get started with the a11y-dialog library, follow these steps:

  1. Install the library using npm or yarn:
npm install a11y-dialog
  1. Import the library and initialize a new dialog instance:
import a11yDialog from 'a11y-dialog';

const dialog = new a11yDialog(document.getElementById('my-dialog'));
  1. Add the necessary HTML structure for the dialog:
<div id="my-dialog" aria-labelledby="dialog-title" aria-describedby="dialog-description" role="dialog">
  <h2 id="dialog-title">Dialog Title</h2>
  <p id="dialog-description">This is the content of the dialog.</p>
  <button type="button" data-a11y-dialog-hide>Close</button>
</div>
  1. Trigger the dialog opening and closing events as needed:
document.getElementById('open-dialog').addEventListener('click', () => {
  dialog.show();
});

document.getElementById('close-dialog').addEventListener('click', () => {
  dialog.hide();
});

That's the basic setup to get started with the a11y-dialog library. You can further customize the dialog's behavior and appearance by passing additional options to the a11yDialog constructor.

Competitor Comparisons

A boilerplate for Sass projects using the 7-1 architecture pattern from Sass Guidelines.

Pros of sass-boilerplate

  • Provides a comprehensive Sass architecture for large projects
  • Includes a well-organized folder structure and naming conventions
  • Offers a collection of useful mixins and functions for Sass development

Cons of sass-boilerplate

  • More complex setup compared to the focused a11y-dialog
  • Requires understanding of Sass and the 7-1 pattern
  • May be overkill for smaller projects or those not using Sass

Code Comparison

sass-boilerplate:

@import 'abstracts/variables';
@import 'abstracts/functions';
@import 'abstracts/mixins';

@import 'base/reset';
@import 'base/typography';

a11y-dialog:

import A11yDialog from 'a11y-dialog';

const dialog = new A11yDialog(document.getElementById('my-dialog'));
dialog.show();

The sass-boilerplate code showcases the modular import structure, while a11y-dialog demonstrates its simple JavaScript implementation for creating accessible dialogs.

sass-boilerplate is ideal for large-scale Sass projects requiring a robust architecture. It provides a solid foundation for organizing styles but may be excessive for smaller projects. a11y-dialog, on the other hand, focuses solely on creating accessible dialog components, making it more suitable for projects specifically needing this functionality. The choice between the two depends on the project's scope and requirements.

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

A11y Dialog

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

Features

  • Follows the Dialog (Modal) pattern from the ARIA Authoring Practices Guide (APG)
  • Supports alert dialogs as per the WAI-ARIA specifications
  • Supports nested dialogs (however questionable)
  • Exposes events to react to changes
  • Provides both a DOM and a JavaScript API
  • Plays nicely with Shadow DOM and web components
  • Is unopinionated with styling
  • Is extensively tested and documented
  • Is fast and tiny

Contributing

Contributing guidelines can be found in CONTRIBUTING.md

NPM DownloadsLast 30 Days