How to prevent click outside React Modal?

13,422

add this line to your modal component

    <ReactModal 
       //other props declaration..
       shouldCloseOnOverlayClick={false} // add this to prevent outside click to prevent modal close 
    >

or use event.preventDefault() to fix it

Share:
13,422
Panayiotis Georgiou
Author by

Panayiotis Georgiou

React.js, GraphQL, Material UI and mobile apps. When I am not writing code πŸ‘¨πŸ»β€πŸ’» I enjoy photography πŸ“·, flying drones 🚁 and playing beach volleyball 🏐or tennis 🎾

Updated on June 15, 2022

Comments

  • Panayiotis Georgiou
    Panayiotis Georgiou almost 2 years

    I'm currently using react-modal package.

    I want to disable click and scroll outside react modal component.

    • Chris
      Chris over 6 years
      You have to show what progress you've done so far. Show us your code and explain what you have tried.
  • Panayiotis Georgiou
    Panayiotis Georgiou over 6 years
    than will do it!
  • Dimitar Christoff
    Dimitar Christoff over 6 years
    if it's a parent element this won't allow closing or interacting with modal either