react bootstrap modal not showing

33,556

Solution 1

I think you may want to refer to this issue on github:

https://github.com/jquense/react-bootstrap-modal/issues/35

The example doesn't seem to be copy and paste ready.

Solution 2

It seems problem with animation use animation={false} <Modal animation={false}> </Modal>

Solution 3

Almost 2 years and the error still occurs. The bug mentioned in the accepted answer is closed without any solution.

The main issue causing this behavior is that the backdrop has the class "fade" applied correctly, but the same class is applied to the modal too. Making the modal invisible.

To overcome this, forcefully override the opacity that is being set by the "fade" class.

<Modal style={{opacity:1}}> </Modal>

Solution 4

Adding fade={false} worked to at least get the modal to display for me.

Solution 5

My solution is

    class Parent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            modal: false
        };
        this.toggle = this.toggle.bind(this);
    };

    toggle() {
        this.setState({modal: !this.state.modal});
    }

    render() {
        return (
            <div>
                <button onClick={ this.toggle}>Contact Us</button>
                <Modal isOpen={this.state.modal} fade={false}
                       toggle={this.toggle} style={{width: "200px", display: "block"}}>
                    <ModalHeader toggle={this.toggle}>
                        Modal title
                    </ModalHeader>
                    <ModalBody>
                        Lorem ipsum dolor sit amet,
                    </ModalBody>
                    <ModalFooter>
                        <Button onClick={this.toggle}>
                            Do Something
                        </Button>{' '}
                        <Button onClick={this.toggle}>Cancel</Button>
                    </ModalFooter>
                </Modal>
            </div>
        );
    }
}
Share:
33,556

Related videos on Youtube

Hisham
Author by

Hisham

Updated on February 09, 2021

Comments

  • Hisham
    Hisham over 3 years

    i want to show react-bootstrap-modal but only the overlay appear and modal not showing

    import Modal from 'react-bootstrap-modal';
    ......
     <Modal
                        show={this.state.open}
                        onHide={this.closeModal}
                        aria-labelledby="ModalHeader"
                    >
                        <Modal.Header closeButton>
                            <Modal.Title id='ModalHeader'>A Title Goes here</Modal.Title>
                        </Modal.Header>
                        <Modal.Body>
                            <p>Some Content here</p>
                        </Modal.Body>
                        <Modal.Footer>
                            // If you don't have anything fancy to do you can use
                            // the convenient `Dismiss` component, it will
                            // trigger `onHide` when clicked
                            <Modal.Dismiss className='btn btn-default'>Cancel</Modal.Dismiss>
    
                            // Or you can create your own dismiss buttons
                            <button className='btn btn-primary'>
                                Save
                            </button>
                        </Modal.Footer>
                    </Modal>
    .....
    

    screenshot:

    image from browser

    • Mark L
      Mark L over 4 years
      Thank you! I spent hours trying to solve this problem when I updated an existing bootstrap 3 + react-bootstrap application to bootstrap 4. This turned out to be the solution. (And this unresolved and apparently longstanding problem has really soured me on react-bootstrap. I won't use it on any new application.)
  • Miodrag Trajanovic
    Miodrag Trajanovic over 5 years
    I am add for fade is false