react bootstrap modal not showing
Asked Answered
S

9

12

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

Stockjobber answered 22/1, 2017 at 20:49 Comment(1)
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.)Hippie
F
0

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.

Finstad answered 23/1, 2017 at 0:35 Comment(0)
D
23

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

Debenture answered 22/4, 2018 at 11:2 Comment(0)
A
19

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>
Alrich answered 8/3, 2019 at 2:55 Comment(0)
B
5

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

Blintz answered 24/4, 2019 at 18:11 Comment(1)
fade={this.state.fade} to <Modal> tag and in state state={ fade: false}Kristinakristine
K
4

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>
        );
    }
}
Kristinakristine answered 7/11, 2018 at 19:35 Comment(1)
I am add for fade is falseKristinakristine
A
4

The issue was not because of "react-bootstrap" package. The issue is: you must have imported bootstrap css and bootstrap css in react-bootstrap package are clashing.

Try importing css as follows:

import "bootstrap/dist/css/bootstrap.min.css";

instead of:

import "./assets/CSS/bootstrap/dist/css/bootstrap.min.css";

As we cannot remove "react-bootstrap" for using modal. So try to remove other css. This fixed the issue for me.

Autarchy answered 8/2, 2021 at 11:47 Comment(0)
B
3

For me it worked with

<Modal show={true}> .... </Modal>

Backcourt answered 5/3, 2022 at 16:40 Comment(1)
I migrated from mui and stupidly accepted that because open apparently exists, it does something... show is the correct prop!Lanchow
F
0

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.

Finstad answered 23/1, 2017 at 0:35 Comment(0)
I
0

Faced the same issue, I had to import all the header, footer & body components individually. This is my solution for React Bootstrap Modal on ReactJS v17.

import Modal from 'react-bootstrap/Modal'
import ModalHeader from 'react-bootstrap/ModalHeader'
import ModalBody from 'react-bootstrap/ModalBody'
import ModalFooter from 'react-bootstrap/ModalFooter'
import Button from 'react-bootstrap/Button'

class Demo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            demoModal: true
        };
    };
    render() {
        return (
            <div>
                <Modal scrollable={true} show={this.state.demoModal} fade={false} style={{ display: "block"}}>
                    <ModalHeader toggle={this.toggle}>
                        Modal title
                    </ModalHeader>
                    <ModalBody>
                        Modal Body
                    </ModalBody>
                    <ModalFooter>
                        <Button onClick={() => this.state({demoModal: false})}>
                            Close
                        </Button>
                    </ModalFooter>
                </Modal>
            </div>
        );
    }
}
Irrigation answered 3/3, 2022 at 8:11 Comment(0)
C
0

This one worked for me:

<Modal show={show} style={{opacity:(show?1:0)}}
Cockleshell answered 12/1, 2024 at 18:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.