Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-dialog-polyfill
Advanced tools
<dialog>
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 <dialog>
element for React.
Differences from most of the existing components:
React.createPortal
, allowing SSR in natively supported browsersz-index
<form>
elementYarn
yarn add react-dialog-polyfill
npm
npm install react-dialog-polyfill
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 (
<div>
<Dialog open={dialog} onClose={(e, dialog) => alert('You closed the dialog')}>
<div>This is a dialog. Click "Close".</div>
<button onClick={() => setDialog(false)}>Close</button>
</Dialog>
<Modal open={modal}
onCancel={(e, dialog) => {
setModal(false)
alert('You canceled the modal')
}}
onClose={(e, dialog) => {
setModal(false)
const value = dialog.returnValue
if (value) alert(`You answered "${dialog.returnValue}" to the modal`)
}}
>
<form method="dialog">
<div>
This is a modal.
Press <pre style={{ display: 'inline-block' }}>Escape</pre> to cancel.
</div>
<div>Do you like modals?</div>
<button type="submit" value="no">No</button>
<button type="submit" value="yes" autoFocus>Yes</button>
</form>
</Modal>
</div>
)
}
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.
FAQs
<dialog> element bundled with polyfill for React
The npm package react-dialog-polyfill receives a total of 710 weekly downloads. As such, react-dialog-polyfill popularity was classified as not popular.
We found that react-dialog-polyfill demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.