[英]React.js mdbottstrap show Modal with click
I would like to open a modal with a click.我想通过单击打开一个模态。 The button is visible on my page, but unfortunately the modal does not open when you click it.
该按钮在我的页面上可见,但不幸的是,当您单击它时,模态不会打开。 Unfortunately I haven't found a solution yet how I can solve the problem.
不幸的是,我还没有找到解决方案,我该如何解决这个问题。
function ModalPage(props) {
const [username, setUsername] = useState();
const [password, setPassword] = useState();
const [showModal, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<MDBContainer>
<MDBBtn rounded onClick={handleShow}>+</MDBBtn>
<MDBModal show={showModal} onHide={handleClose}>
<MDBModalHeader className="text-center" titleClass="w-100 font-weight-bold">Data Input</MDBModalHeader>
<MDBModalBody>
<form className="mx-3 grey-text">
<MDBInput label="ID" group type="text" validate />
<MDBInput label="Username" group type="email" validate error="wrong" success="right"
onChange={(evt) => setUsername(evt.target.value)}
/>
<MDBInput label="Password" group type="text"
onChange={(evt) => setPassword(evt.target.value)}
/>
<MDBInput type="textarea" rows="2" label="Your message" />
</form>
</MDBModalBody>
<MDBModalFooter className="justify-content-center">
<MDBBtn color="unique" onClick={handleClose}>Send
<MDBIcon far icon="paper-plane" className="ml-2" />
</MDBBtn>
</MDBModalFooter>
</MDBModal>
</MDBContainer>
);
}
export default withRouter(ModalPage);
According to this MDB page , the property used to dictate whether or not a modal is being shown is not show
, but rather isOpen
.根据此 MDB 页面,用于指示是否显示模式的属性不是
show
,而是isOpen
。 Change改变
<MDBModal show={showModal} onHide={handleClose}>
To到
<MDBModal isOpen={showModal} onHide={handleClose}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.