react bootstrap modal not showing

五迷三道 提交于 2020-01-14 12:37:57

问题


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:


回答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.




回答2:


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




回答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>



回答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>
        );
    }
}



回答5:


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



来源:https://stackoverflow.com/questions/41795987/react-bootstrap-modal-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!