项目作者: Meemaw

项目描述 :
Accessible, lightweight and configurable modal component with a11y-enabled.
高级语言: TypeScript
项目地址: git://github.com/Meemaw/react-micro-modal.git
创建时间: 2019-04-01T13:48:09Z
项目社区:https://github.com/Meemaw/react-micro-modal

开源协议:MIT License

下载


react-micro-modal

npm CI codecov code style: prettier

Accessible, lightweight and configurable modal component with a11y-enabled inspired by Micromodal.js.

Release notes | Documentation


  • NPM: npm install react-micro-modal
  • Yarn: yarn add react-micro-modal

Features

  • Micro bundle - 1.9 KB 📦
  • a11y friendly 👓
  • Supports nested modals
  • Focuses on the first focusable element within the modal
  • Traps focus inside the modal
  • Closes on document click
  • Closes on Escape keypress
  • Usage as controlled or uncontrolled component

Example

Here is a minimal uncontrolled modal example in 3 lines of code.

  1. import React from 'react';
  2. import { render } from 'react-dom';
  3. import MicroModal from 'react-micro-modal';
  4. const App = () => {
  5. return (
  6. <MicroModal trigger={(open) => <div onClick={open}>Open!</div>}>
  7. {(close) => <button onClick={close}>Close!</button>}
  8. </MicroModal>
  9. );
  10. };
  11. render(<App ></App>, document.getElementById('root'));

Live Playground

For more examples of micro-modal in action, go to https://meemaw.github.io/react-micro-modal.

OR

To run that demo on your own computer: