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

Fabian Schultz
  • 18,138
  • 5
  • 49
  • 56
Hisham
  • 143
  • 2
  • 2
  • 6
  • 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.) – Mark L Mar 26 '20 at 14:04

8 Answers8

23

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

Vipin Shukla
  • 235
  • 2
  • 4
17

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>
Pranav Vikram
  • 301
  • 2
  • 3
5

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

Andrew Watters
  • 223
  • 4
  • 9
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>
        );
    }
}
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.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
2

For me it worked with

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

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.

Alexg2195
  • 605
  • 7
  • 18
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>
        );
    }
}
Rahul Dasgupta
  • 463
  • 8
  • 14