question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onClick() not working for the nested links on ReactModal Window

See original GitHub issue

Summary:

I need to create a pop-up Modal Window which has multiple side-tabbed panes and on clicking of these tabs each of them renders a new component inside the Modal Window. I am using a Redux approach to create reusable Modal Windows across my application. I try clicking on the various links but no action or console.log are shown.

Steps to reproduce:

  1. REUSBALE WRAPPER FOR REDUX MODALS `import React from ‘react’; import PropTypes from ‘prop-types’; import { connect } from ‘react-redux’; import ReactModal from ‘react-modal’; import FiltersModals from ‘./filtersModal’; import { MODAL_TYPE_FILTERS } from ‘…/…/constants/modalConstants’; import styles from ‘./styles.css’;

const MODAL_TYPES = { ‘alert’: FiltersModals } const mapStateToProps = state => ({ …state.modal }) class ModalRoot extends React.Component { constructor(props) { super(props); this.state = { modalIsOpen: false }; this.closeModal = this.closeModal.bind(this) }

componentWillReceiveProps(nextProps) { if (nextProps !== this.props) { this.setState({ modalIsOpen: nextProps.modalProps.open }) } } closeModal() { this.setState({ modalIsOpen: false }) } render() { if (!this.props.modalType) { return null } const SpecifiedModal = MODAL_TYPES[this.props.modalType]; return ( <div> <ReactModal isOpen={this.state.modalIsOpen} onRequestClose={this.closeModal} contentLabel="Example Modal" ariaHideApp={false} className="Modal" overlayClassName="Overlay" bodyOpenClassName="bodyModal" > <SpecifiedModal closeModal={this.closeModal} {…this.props.modalProps} /> </ReactModal> </div> ) } } export default connect(mapStateToProps, null)(ModalRoot) 2. COMPONENT RENDERED INSIDE THE MODAL WINDOW WITH MULTIPLE LINKSimport React, {Component} from ‘react’; import ‘bootstrap/dist/css/bootstrap.min.css’; import styles from ‘./styles.css’; import LineAwesome from “…/line-awesome”;

class filtersModal extends Component {

constructor() { super(); this.state = { selectedComponentSet: ‘Country’ } }

handleLinkClick(link) { this.setState({selectedComponentSet: link}); }

render() { const {closeModal, title, message} = this.props; switch (this.state.selectedComponentSet) { case ‘Regions’: componentSet = (<div className="component"> I am a Regions Checkbox component! </div>); break; case ‘Countries’: componentSet = (<div className="component"> I am a Countries Checkbox component! </div>); break; case ‘Sectors’: componentSet = (<div className="component"> I am a Sectors Checkbox component! </div>); break; case ‘PortfolioManager’: componentSet = (<div className="component"> I am a PortfolioManager Checkbox component! </div>); break; case ‘Range’: componentSet = (<div className="component"> I am a Range Checkbox component! </div>); break; }

return (<div className="modal-dialog modal-lg ts-modal modal-dialog-centered">
  <div className={styles.modalContentTX}>
    <div className={styles.modalHeaderTX}>
      <h5 className={styles.modalTitleTX}>{title}</h5>
      <button type="button" data-dismiss="modal" aria-label="Close" onClick={closeModal}>
        <span className="la la-close"></span>
      </button>
    </div>
    <div className={styles.modalBodyTX}>
      <div className={styles.modalTabsLeftTX}>
        <div className={styles.tabNavContainer}>
          <ul className={styles.ulNavTX}>
            <li className={this.state.selectedComponentSet === 'Regions'
                ? 'active'
                : 'null'} onClick={this.handleLinkClick.bind(this, 'Regions')}>Regions</li>
            <li className={this.state.selectedComponentSet === 'Countries'
                ? 'active'
                : 'null'} onClick={this.handleLinkClick.bind(this, 'Countries')}>Countries</li>
            <li className={this.state.selectedComponentSet === 'Sectors'
                ? 'active'
                : 'null'} onClick={this.handleLinkClick.bind(this, 'Sectors')}>Sectors</li>
            <li className={this.state.selectedComponentSet === 'PortfolioManager'
                ? 'active'
                : 'null'} onClick={this.handleLinkClick.bind(this, 'PortfolioManager')}>Portfolio Manager</li>
            <li className={this.state.selectedComponentSet === 'Range'
                ? 'active'
                : 'null'} onClick={this.handleLinkClick.bind(this, 'Range')}>Range</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</div>);

} }

export default filtersModal; `

Expected behavior:

Link to example of issue:

Additional notes:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
diasbrunocommented, Sep 30, 2018

The modal-dialog class has the property pointer-events: none; which will prevent the mouse events to get to those elements on the list.

1reaction
PalsRoycommented, Sep 30, 2018

I though so, as a workaround I will create my own css classes to control the properties of the modal window because event propagation is more important from the application point of view. Thank you again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

onClick not working on first click in react nested component
I edited the test function like this : const test = () => setActiveStep((prevActiveStep) => prevActiveStep + 1); or const test = (e)...
Read more >
<Modal/> Component - React-Bootstrap
Modals are unmounted when closed. Bootstrap only supports one modal window at a time. Nested modals aren't supported, but if you really need...
Read more >
React Modal component - Material UI - MUI
Modals can be nested, for example a select within a dialog, but stacking of more than two modals, or any two modals with...
Read more >
How to render modals in React - freeCodeCamp
One strategy is to use ReactDOM portals, and put the modal in a div that is a sibling component to the div with...
Read more >
Portals - React
render() { // React does *not* create a new div. It renders the children into `domNode`. // `domNode` is any valid DOM node,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found