Skip to content

sargalias/react-modal

Repository files navigation

React Accessible Modal

This project is an example of a modal (dialog) component made with React. It's made to be simple and accessible. It purposely doesn't use the dialog's showModal and hideModal methods because they handle all the heavy lifting for accessibility and functionality.

It's not necesssarily complete. It's just a quick example. For example, it doesn't have tests for all props. Also, I haven't thoroughly tested its accessibility with screen readers.

The main component is the Modal component. I tried to make it the "react way" where the parent either renders the modal or doesn't. This contrasts the HTML way where the modal is always open and its open attribute is toggled either directly or through its methods.

Alternative methods would be to:

  • Let HTML handle the heavy lifting. Use the dialog component along with the showModal and hideModal methods. They handle the majority of accessibility issues including closing the modal when Escape is pressed, focus trapping and changing the initial focus.
  • Allow the modal stay rendered and instead close / open with by passing an open prop from the parent.

View project

Table of contents

Getting started with Docker

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

  1. Make sure Docker and docker compose are installed and that you're able to run containers. Please see Docker installation instructions.
  2. Clone the repo
git clone https://github.com/sargalias/react-modal
  1. Open a terminal and cd into the react-modal folder.
  2. Run docker compose up
  3. Visit http://localhost:3000 in your browser.

Getting started with Node and NPM

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • NPM

Installation requires NPM which is included with Node. You can install Node by downloading the installer from the website.

To update NPM to the latest version:

npm install -g npm

Installation

  1. Clone the repo
git clone https://github.com/sargalias/react-modal
  1. Install NPM packages
npm install

Running the project for development

npm start

Usage

Starting the project

  • Start the project on a local server: npm start

Building the project

  • Build the project for production: npm run build

Built with

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

This project is an example of a modal (dialog) component made with React. It's made to be simple and accessible.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published