CodePen
codepen.io › shantanu-jana › pen › eYVbGvp
Modal Popup in React JS
/*#__PURE__*/ React.createElement("div", { className: "popup" }, /*#__PURE__*/ React.createElement("div", { className: "popup-inner" }, /*#__PURE__*/ React.createElement("button", { className: "close-btn", onClick: () => props.setTrigger(false) }, "close"), props.children)) : null; } function App(props) { const [popup, setPopup] = useState(false); return /*#__PURE__*/( React.createElement("div", null, /*#__PURE__*/ React.createElement("main", null, /*#__PURE__*/ React.createElement("br", null), /*#__PURE__*/ React.createElement("button", { onClick: () => setPopup(true) }, "Open Popup")), /*#__PURE__*/ React.createElement(Popup, { trigger: popup, setTrigger: setPopup }, /*#__PURE__*/ React.createElement("h3", null, "My popup"), React.createElement("h6", null, "Lorem ipsum dolor sit, amet consectetur adipisicing elit.
LogRocket
blog.logrocket.com › home › creating a reusable pop-up modal in react from scratch
Creating a reusable pop-up modal in React from scratch - LogRocket Blog
January 13, 2025 - See the Pen The native <dialog> modal: CSS Styling by Rahul (@_rahul) on CodePen. Notice how the previously mentioned backdrop area works. When the modal is open, you’re not able to click on anything in the background until you click the Close button. Don't miss a moment with The Replay, a curated newsletter from LogRocket · Learn how LogRocket's Galileo AI watches sessions for you and proactively surfaces the highest-impact things you should work on · Use React's useEffect to optimize your application's performance
Videos
CodePen
codepen.io › kotomoika › pen › RVOKxR
Modal window with React.js
.modal z-index 9999 position absolute top 50% left 50% min-width 250px min-height 100px padding 15px border-radius 10px transform translate(-50%, -50%) background #fff .bg z-index 9998 position absolute width 100% height 100% top 0 left 0 background rgba(0, 0, 0, 0.3) ... class App extends React.Component { constructor(props) { super(props) this.state = { isModalOpen: false } } render() { return ( <div> <button onClick={() => this.openModal()}>Open modal</button> <Modal isOpen={this.state.isModalOpen} onClose={() => this.closeModal()}> <h3>Modal title</h3> <p>Content</p> </Modal> </div> ) } op
CodePen
codepen.io › deammer › pen › LoMBvp
React modal using hooks
const { useState, useEffect } = React; const Modal = ({ onRequestClose }) => { // Use useEffect to add an event listener to the document useEffect(() => { function onKeyDown(event) { if (event.keyCode === 27) { // Close the modal when the Escape key is pressed onRequestClose(); } } // Prevent scolling document.body.style.overflow = "hidden"; document.addEventListener("keydown", onKeyDown); // Clear things up when unmounting this component return () => { document.body.style.overflow = "visible"; document.removeEventListener("keydown", onKeyDown); }; }); return ( <div className="modal__backdrop"> <div className="modal__container"> <h3 className="modal__title">I'm a modal!</h3> <p> When this modal is open, we disable scrolling the <code>body</code> using{" "} <code>overflow: hidden</code>. This allows users to scroll the modal without losing their position on the page.
CodePen
codepen.io › carloluis › pen › owQoQr
react-modal
const { render } = ReactDOM; const noop = () => {}; function create(Component, props) { return new Promise((resolve, reject) => { const root = document.body; const wrapper = document.getElementById('modal'); const cleanup = () => { ReactDOM.unmountComponentAtNode(wrapper); root.classList.remove('no-overflow'); //wrapper.remove(); }; root.classList.add('no-overflow'); const response = func => response => { cleanup(); func(response); }; const viewProps = { accept: response(resolve), close: response(reject) }; ReactDOM.render(<Component {...props} {...viewProps} />, wrapper); }); } class Modal ex
CodePen
codepen.io › baranovxyz › pen › pojLjjB
Simple Modal in React - CodePen
JS Options · Format JavaScript · View Compiled JavaScript · Analyze JavaScript · Maximize JavaScript Editor · Minimize JavaScript Editor · Fold All · Unfold All · const { useState, useEffect } = React; const root = document.getElementById('root'); const Modal = ({ children }) => <div className='Modal'>{children}</div>; const Component = () => <div className="Component">Component in modal, click or press Esc to close</div> const App = () => { const [showModal, setShowModal] = useState(false); const handleKeyup = e => e.keyCode === 27 && setShowModal(false); const toggleModal = () => set
CodePen
codepen.io › mike-grifin › pen › bwNQdQ
React Modal Ui
JS Options · Format JavaScript · View Compiled JavaScript · Analyze JavaScript · Maximize JavaScript Editor · Minimize JavaScript Editor · Fold All · Unfold All · const App = React.createClass({ getInitialState : function() { return({ modal: false }); }, modalToggle : function() { this.setState({modal: !this.state.modal}) }, render : function(){ return( <div> <button className="place-order" onClick={this.modalToggle}> <span className="fa fa-shopping-cart"></span> </button> <Modal onClick={this.modalToggle} status={this.state.modal}/> </div> ); } }); const Modal = React.createClass({ getDefaultProps : function(){ return({ title: "Ova Highchair", description: "From formula to fruits, your baby's got a lot of eating ahead.
CodePen
codepen.io › ph1p › pen › XjNONb
Easy react modal
class Modal extends React.Component { static propTypes = { isModalOpen: React.PropTypes.bool.isRequired, closeModal: React.PropTypes.func.isRequired, style: React.PropTypes.shape({ modal: React.PropTypes.object, overlay: React.PropTypes.object }) }; constructor(props) { super(props); this.outerStyle = { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", overflow: "auto", zIndex: 1 }; // default style this.style = { modal: { position: "relative", width: 500, padding: 20, boxSizing: "border-box", backgroundColor: "#fff", margin: "40px auto", borderRadius: 3, zIndex: 2, textAlign:
CodePen
codepen.io › focuswish › pen › ENJjzL
React Modal Example
JS Options · Format JavaScript · View Compiled JavaScript · Analyze JavaScript · Maximize JavaScript Editor · Minimize JavaScript Editor · Fold All · Unfold All · const display = { display: 'block' }; const hide = { display: 'none' }; class Modal extends React.Component { constructor(props) { super(props); this.toggle = this.toggle.bind(this); this.state = { toggle: false } } toggle(event) { this.setState((prevState) => ({ toggle: !prevState.toggle })); } render() { var modal = []; modal.push( <div className="modal" style={this.state.toggle ?
CodePen
codepen.io › eedamame › pen › OxNejY
react-modal sample
class ExampleApp extends React.Component { constructor () { super(); this.state = { showModal: false }; this.handleOpenModal = this.handleOpenModal.bind(this); this.handleCloseModal = this.handleCloseModal.bind(this); } handleOpenModal () { this.setState({ showModal: true }); } handleCloseModal () { this.setState({ showModal: false }); } render () { return ( <div> <button onClick={this.handleOpenModal}>Trigger Modal</button> <ReactModal isOpen={this.state.showModal} contentLabel="Minimal Modal Example" className="Modal" overlayClassName="Overlay" onRequestClose={this.handleCloseModal} > <div>モーダル</div> <button onClick={this.handleCloseModal}>Close Modal</button> </ReactModal> </div> ); } } const props = {}; ReactDOM.render(<ExampleApp {...props} />, document.getElementById('main'))
CodePen
codepen.io › minhtranite › pen › yYqXpP
React Modal Bootstrap
var Modal = window.ReactModalBootstrap.Modal; var ModalHeader = window.ReactModalBootstrap.ModalHeader; var ModalTitle = window.ReactModalBootstrap.ModalTitle; var ModalClose = window.ReactModalBootstrap.ModalClose; var ModalBody = window.ReactModalBootstrap.ModalBody; var ModalFooter = window.ReactModalBootstrap.ModalFooter; class App extends React.Component { state = { isOpen: false, isSubOpen: false }; openModal = () => { this.setState({ isOpen: true }); }; hideModal = () => { this.setState({ isOpen: false }); }; openSubModal = () => { this.setState({ isSubOpen: true }); }; hideSubModal = (
CodePen
codepen.io › bere › pen › PmrQKy
Simple Modal in React (ES6)
/** * App.js * Create a custom <Modal/> component to display dynamic content */ class App extends React.Component { constructor(props) { super(props); // Init state this.state = { modalOpen: props.opened, pic: props.welcomePicture}; } // Toggle Modal visibility toggleModal(pic) { const state = this.state.modalOpen; // Update state: modal visibility and its content this.setState({ modalOpen: !state, pic }); } render() { const { modalOpen, pic } = this.state; return ( <div> { /* Modal */ } <Modal bg="#222" show={ modalOpen } onClose={ this.toggleModal.bind(this) }> <img src={ pic } /> </Modal> {
CodePen
codepen.io › andreasmcdermott › pen › LQNpbg
Bootstrap modal example (React modal)
// Instead the component expects a onClose callback that will be called when user clicks "Close". function MediaModal({children, onClose}) { return ( <div className="modal show" style={{display: 'block'}} > <div className="modal-dialog" role="document"> <div className="modal-content"> <div className="modal-header"> <h5 className="modal-title">Modal title</h5> <button type="button" className="close" aria-label="Close" onClick={onClose} > <span aria-hidden="true">×</span> </button> </div> <div className="modal-body">{children}</div> <div className="modal-footer"> <button className="btn btn-secondary" onClick={onClose} >Close</button> </div> </div> </div> </div> ); } ReactDOM.render( <MediaModal> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
CodePen
codepen.io › fidelscodes › pen › ygYRXV
React Modal Example - CodePen
JS Options · Format JavaScript · View Compiled JavaScript · Analyze JavaScript · Maximize JavaScript Editor · Minimize JavaScript Editor · Fold All · Unfold All · class App extends React.Component { constructor(props) { super(props); this.state = { // modal should be closed on page load isModalOpen: false }; // binding methods this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } openModal() { this.setState({ isModalOpen: true}) } closeModal () { this.setState({ isModalOpen: false }) } render () { return ( <div> <button onClick={this.openModal}>Open the modal</button> <Modal isOpen={this.state.isModalOpen} onClose={this.closeModal}/> </div> ); } } // <Modal /> class Modal extends React.Component { render () { const { isOpen, onClose } = this.props; return ( <div className={isOpen ?
CodePen
codepen.io › joykureel › pen › RXKRqv
hover popup modal in react
class App extends React.Component{ state={ likeList:'' } renderLikeList = () =>{ return <div className="likes__list" >Likes to be rendered specifically</div> } handleLeave=()=>{ return this.setState({likeList:''}) } handleHover=()=>{ return this.setState({likeList:this.renderLikeList()}) } render(){ return( <div className="likes__wrapper" > <div className="likes__relavance" onMouseOver={this.handleHover} onMouseLeave={this.handleLeave}> Hover me {this.state.likeList} </div> </div> ) } } ReactDOM.render(<App/>,document.getElementById('root'));
CodePen
codepen.io › Laumak › pen › pRJzGL
React + Bulma Modal
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing. If active, Pens will autosave every 30 seconds after being saved once. If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update. If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting. ... Visit your global Editor Settings. ... const Modal = ({ children, closeModal, modalState, title }) => { if(!modalState) { return null; } return( <div className="modal is-active"> <div className="modal-bac
Reddit
reddit.com › r/reactjs › what is best way to create popup modal in react js
r/reactjs on Reddit: What is best way to create popup modal in react js
March 12, 2023 -
Wanto create popup in react js site. Is react portal is best way to create popup?
CodePen
codepen.io › tag › react-modal
Pens tagged 'react-modal' on CodePen
CodePen doesn't work very well without JavaScript · We're all for progressive enhancement, but CodePen is a bit unique in that it's all about writing and showing front end code, including JavaScript. It's required to use most of the features of CodePen · Need to know how to enable it?
CodePen
codepen.io › andreasmcdermott › pen › wyGKmW
Bootstrap modal example (with React modal hooked up)
// Render this.render(); } // Called by application to open modal. open(content) { // Update state and rerender open this.isOpen = true; this.content = content; this.render(); } handleClose = () => { // Update state and rerender closed this.isOpen = false; this.render(); }; render() { // Our wrappers for dialogs generally include a div that is always rendered, even when the dialog is closed. // The alternative would be to render the modal on open and then remove it from the DOM on closed using React.unmountComponentAtNode.