<dialog> element bundled with polyfill for React
npm install react-dialog-polyfill    
element bundled with polyfill for React
While many other more feature-rich React modal components exists, react-dialog-polyfill
aims to be a simple binding of the native element for React.
Differences from most of the existing components:
- Native browser support in browsers like Chrome and Opera
- Polyfill for un-supported browsers
- Avoids using React.createPortal, allowing SSR in natively supported browsers
- Dialog always will display in-front of other elements regardless of z-index
- Selected info from dialog can be returned via element
- Well suited for Electron apps
Yarn
``yarn`
yarn add react-dialog-polyfill
npm
`npm`
npm install react-dialog-polyfill
`jsx
import React, { useState } from 'react'
import { Modal, Dialog } from 'react-dialog-polyfill'
const App = () => {
const [dialog, setDialog] = useState(true)
const [modal, setModal] = useState(true)
return (
)
}}
>
export default App
`
Simply add the desired component to the React application using JSX.
The Modal component will block interaction with other elements when it is open, while the Dialog component will not.
open indicates if the modal is open. Default: false
onClose runs when the modal is explicitly closed. Default: (event, modal) => {}
That is the open prop state is toggled from true to false.
This means that having onCancel={() => setModal(false)} will call onClose from within onCancel.
onCancel runs when the modal is canceled using Escape. Default: (event, modal) => {}
By default the modal itself will not close as open will still be set however the event will trigger.
It is recommended to set onCancel={() => setModal(false)} to have the modal close when Escape` is pressed.