An open API service indexing awesome lists of open source software.

https://github.com/prolific-digital/bare-modal

Bare Modal is a lightweight JS library for accessible modals using the `<dialog>` tag. Features automatic bindings, cookie tracking, timed displays, and WCAG compliance for enhanced user engagement and accessibility.
https://github.com/prolific-digital/bare-modal

accessibility bare easy-to-use html5 javascript modal native

Last synced: 3 months ago
JSON representation

Bare Modal is a lightweight JS library for accessible modals using the `<dialog>` tag. Features automatic bindings, cookie tracking, timed displays, and WCAG compliance for enhanced user engagement and accessibility.

Awesome Lists containing this project

README

        

# Bare Modal

Bare Modal is a lightweight, accessible modal library designed to enhance user interaction on web applications. Utilizing the native HTML `` element, it offers an easy and robust solution for implementing modals with features like automatic action binding, cookie-based user action tracking, customizable cookie durations, and timed modal displays.

## Features

- **Native HTML `` Support**: Uses the HTML `` element for ease of use and accessibility.
- **Automatic Action Binding**: Simplifies modal interactions with data attributes for open, close, accept, and cancel actions.
- **Cookie-Based Action Tracking**: Remembers user modal interactions to prevent redundant displays.
- **Customizable Cookie Duration**: Allows developers to define how long modal actions are remembered.
- **Timed Modal Display**: Enables modals to appear after a set delay, enhancing user engagement.
- **Accessibility**: Ensures modals are accessible, following WCAG guidelines for inclusive design.

## Installation

Include Bare Modal in your project by adding the `bare-modal.min.js` file to your codebase and linking to it within your HTML file:

```html

```

## Usage

### Basic Modal

```html
Open Modal

This is a simple modal.


Close

```

### Timed Modal

```html

This modal will display after 5 seconds.


Close

```

### Custom Cookie Duration

```html

Cookie duration for this modal's action is 30 days.


Close

```

## API

### `data-modal-trigger="ID"`

Triggers the modal with the specified ID to open.

### `data-modal-close`

Closes the modal.

### `data-modal-accept`

Marks the modal as accepted and closes it. Useful for confirmation dialogs.

### `data-modal-cancel`

Marks the modal as canceled and closes it. Useful for confirmation dialogs.

### `data-modal-timed="SECONDS"`

Delays the modal's display for the specified number of seconds.

### `data-modal-cookie-expire="DAYS"`

Sets the duration for which the user's action on the modal is remembered.

## Accessibility

Bare Modal leverages the `` element's inherent accessibility features, such as focus management and semantic structure. It adheres to WCAG guidelines, ensuring that modals are accessible to all users, including those using assistive technologies.

## Best Practices

- **Test Across Devices**: Ensure modals perform well on various devices and screen sizes.
- **Keyboard Navigation**: Verify modals are fully navigable using the keyboard.
- **Screen Reader Testing**: Regularly test your modals with screen readers to ensure they are announced and interacted with correctly.

## Contributing

Contributions are welcome! If you have suggestions for improving Bare Modal, please open an issue or submit a pull request.

## License

Bare Modal is open-source software licensed under the MIT license.