
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
@types/react-modal
Advanced tools
TypeScript definitions for react-modal
@types/react-modal provides TypeScript type definitions for the react-modal library, which is a popular library for creating accessible modal dialogs in React applications.
Basic Modal Usage
This code demonstrates the basic usage of react-modal with TypeScript. It shows how to open and close a modal dialog.
import React from 'react';
import Modal from 'react-modal';
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
Custom Styles
This code demonstrates how to apply custom styles to the modal dialog using the style prop.
import React from 'react';
import Modal from 'react-modal';
const customStyles = {
content: {
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)'
}
};
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
style={customStyles}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
Accessibility Features
This code demonstrates how to set the app element for accessibility purposes, ensuring that screen readers can properly interact with the modal.
import React from 'react';
import Modal from 'react-modal';
Modal.setAppElement('#root');
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
react-bootstrap provides a set of React components built using Bootstrap. It includes a Modal component that offers similar functionality to react-modal but with Bootstrap styling and additional features.
material-ui is a popular React UI framework that includes a Dialog component. It provides a wide range of customization options and integrates well with the Material Design system.
semantic-ui-react offers a collection of React components based on Semantic UI. It includes a Modal component that provides similar functionality to react-modal with Semantic UI styling.
npm install --save @types/react-modal
This package contains type definitions for react-modal (https://github.com/reactjs/react-modal).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-modal.
These definitions were written by Rajab Shakirov, Drew Noakes, Thomas B Homburg, Tatu Tamminen, Uwe Wiemer, Peter Blazejewicz, Justin Powell, Juwan Wheatley, Nitzan Mousan, and dkrk.
FAQs
TypeScript definitions for react-modal
The npm package @types/react-modal receives a total of 957,462 weekly downloads. As such, @types/react-modal popularity was classified as popular.
We found that @types/react-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.