Tags down


React: How to close a modal from child opened from parent component

By : Davood Khani
Date : October 18 2020, 06:10 PM
With these it helps You need to pass a callback as a props in Child component, it will update Parent Component when you click on closeButton in child.
code :
// Parent Component
callbackModal = () => {
   this.setState({ showModal: false });
closeButtonClickHandler = () => {

Share : facebook icon twitter icon

React Native : Show parent component after closing a modal on child component

By : Yuzong
Date : March 29 2020, 07:55 AM
I hope this helps you . I have two components a Parent Component (App.js) and a Child Component (Logitem.js) , -Simple in deleteSelectedRecord function call setModalVisible(false)

React: Closing Modal in Child Component from Parent

By : Christopher Norman
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a modal in a child component that handles a delete function in the parent component. The child is holding the state of the modal (open or closed) as this seems the most logical place for it. , You could use a ref to call the child close function?
code :
    removeItem() {

   render() {
      return (
            <ChildWithModal ref={(ref) => { this.child = ref; }} />

close() {
   this.setState({ showModal: false })

React component tree close previously opened parent node

By : Toscino
Date : March 29 2020, 07:55 AM
With these it helps I'm not going to edit the Codepen and do all the work for you, but I'll give you a general idea of how to achieve your requirements.
code :
state = {
  expanded: {},
this.setState(prevState => ({
  expanded: {
    ...prevState.expanded, // leave other panels expanded
    [tierOne.name]: true,
  expanded: {
    [tierOne.name] : true, // collapse all other panels
if (state.expanded[tierOne.name]) this.setState({ expanded: {} });

Closing react-bootstrap popup modal by passing function from parent component to child component via props not updating

By : Sebastian
Date : March 29 2020, 07:55 AM
like below fixes the issue In togglePopup you use value from props, that is always undefined. You should use this.state.open
code :
togglePopup() {
        open: !this.state.open

react Portal - how to close modal when clicking outside of modal and how to assign ref to modal inside parent component

By : user3452325
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Since the click listener will be applied to all modal instances, I'd move the listener and the ref to a reuseable modal component -- now it'll control clicks once opened. The only thing it really needs is a passed down toggle modal function prop from the parent.
Working example:
code :
import React, { Fragment, PureComponent } from "react";
import { createPortal } from "react-dom";
import PropTypes from "prop-types";

class Modal extends PureComponent {
  componentDidMount() {
    document.addEventListener("click", this.closeModal, false);

  componentWillUnmount() {
    document.removeEventListener("click", this.closeModal, false);

  closeModal = ({ target }) => {
    if (this.modal && !this.modal.contains(target)) {

  render = () =>
        <div className="overlay" />
        <div className="window-container">
          <div className="modal-container">
            <div ref={node => (this.modal = node)} className="modal">

Modal.propTypes = {
  children: PropTypes.node.isRequired,
  toggleModal: PropTypes.func.isRequired

export default Modal;
import React, { Component } from "react";
import Modal from "../Modal";

class Parent extends Component {
  state = {
    showModal: false

  toggleModal = () => {
    this.setState(prevState => ({
      showModal: !prevState.showModal

  render = () => (
    <div className={`${this.state.showModal ? "blur" : undefined} app`}>
      {this.state.showModal && (
        <Modal toggleModal={this.toggleModal}>
          <h1 className="title">Hello!</h1>
          <p className="subtitle">There are two ways to close this modal</p>
            <li>Click outside of this modal in the grey overlay area.</li>
            <li>Click the close button below.</li>
            className="uk-button uk-button-danger uk-button-small"

export default Parent;
.app {
  text-align: center;
  margin-top: 20px;

.blur > img {
  -webkit-filter: blur(10px);
  -moz-filter: blur(10px);
  -ms-filter: blur(10px);
  -o-filter: blur(10px);
  filter: blur(10px);

.image {
  display: block;
  margin: 0 auto;
  cursor: pointer;
  width: 600px;

.modal {
  max-width: 600px;
  max-height: calc(100% - 96px);
  padding: 20px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  position: relative;
  overflow-y: auto;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-shadow: 0px 11px 15px -7px rgba(0, 0, 0, 0.2),
    0px 24px 38px 3px rgba(0, 0, 0, 0.14), 0px 9px 46px 8px rgba(0, 0, 0, 0.12);
  box-shadow: 0px 11px 15px -7px rgba(0, 0, 0, 0.2),
    0px 24px 38px 3px rgba(0, 0, 0, 0.14), 0px 9px 46px 8px rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  background-color: #fff;
  text-align: left;

.modal-container {
  opacity: 1;
  -webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  -o-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  height: 100%;
  outline: none;

.overlay {
  opacity: 1;
  -webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  -o-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  position: fixed;
  -ms-touch-action: none;
  touch-action: none;
  background-color: rgba(0, 0, 0, 0.5);
  -webkit-tap-highlight-color: transparent;

.subtitle {
  margin: 0;
  text-align: center;
  font-weight: bold;

.title {
  text-align: center;

.window-container {
  text-align: center;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  outline: 0;
  -webkit-animation: fadeIn 0.2s 0s ease-in-out forwards;
  animation: fadeIn 0.2s 0s ease-in-out forwards;
  z-index: 100;
Related Posts Related Posts :
  • How do I add a counter to show how many times a div element has been clicked?
  • Calling A function using vue.js components and properties
  • How to check type of "typeof" in JavaScript?
  • Recursive function to determine if number is even or odd by subtracting two from n until n = 0 or 1
  • How to fix:"Refused to run the JavaScript URL because it violates the following Content Security Policy..."
  • Can't access value inside of props object
  • How map and filter over array of objects?
  • How to invert d3 color ramps d3-scale-chromatic d3.interpolateViridis
  • Comparing two variables JavaScript
  • Google Pay & Web Payment Request API:
  • How to pass date as parameter in javascript function
  • why i have this error "Expected an assignment or function call and instead saw an expression no-unused-expressions&
  • calculate the full turns of a circle
  • Applying spread operator on object with getter
  • How do I hide a parent div when child div contains a certain text?
  • How to Stream Live Audio With Low Latency
  • how to find tab close and clear local storage
  • Function returning undefined value, a bit confused
  • Assignment involving generic property of generic object fails to typecheck correctly within generic function
  • What is output for foo.x
  • Remove singular element from an object's key array
  • How to fix lag issue over time in my Three.js game
  • async await promise.all map not resolving promises
  • Print an HTML document to PDF using JavaScript
  • Getting illegal invocation, after using $.ajax inside of $(doocument).keypress function
  • DebounceTime emits all the events which was captred during the time
  • Mongoose 5.x disallows passing a spread of operators
  • javascript onkeypress limit characters when pasting
  • How to fire an event only if specific-time has lapsed after scrolling has been stopped
  • How to filter an array of objects based on another array of objects?
  • Best way to switch between two colours with javascript?
  • Calling asynchronous function but returning result synchronously
  • Can't inject custom repository
  • How do I fix the Cordova error: Failed to fetch platform <<<<< HEAD?
  • Javascript: Store a global variable for a single page application
  • Node: Load/read the content of a page from external website(domain)
  • What is the difference between Object and object type
  • How to detect focusout on parent div not on child div in Angular4
  • How to end program after right answer?
  • How to use dot notation after +
  • Error from anonymous function: unexpected token <
  • Refresh a particular component in Angular
  • RegEx for validating three alphanumeric conditions
  • How to upload html file in the google and let it view by everyone?
  • Use Array.map on an 2-dimensional Array
  • Not sure whether I have syntax errors or errors with the code
  • How to fix process.nextTick is not a function with Calgolia places.js?
  • React Text Annotation
  • Is it possible to change the input type of an input element inside a <td> using <td> id with the use of java
  • Render functional component on variable change
  • Using Javascript to write a function which compares two trees and returns true if they are equal in structure and in val
  • How to save results from dynamic cascading drop down list?
  • How to pass arguments to function in functional component in React
  • Is there a way to view the contents of a predefined function like alert()?
  • object use own method in javascript
  • How do I replace NaN with 0 when doing division in javascript?
  • How to separate input field values in React?
  • How to link two JavaScript files together? NO HTML
  • Angular 7 - how to make initial input value visible for JSON?
  • How to get previous state value in reactjs
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk