【发布时间】:2017-11-22 02:25:50
【问题描述】:
我正在使用来自here 的 React 引导程序中的 Modal 组件,我可以使用以下代码轻松实现 Modal,
import React, {Component} from 'react';
import {BaseComponent} from 'BaseComponent';
import { Modal, Button } from 'react-bootstrap';
class InteractiveMap extends BaseComponent {
constructor(props) {
super(props);
this.open = this.open.bind(this);
this.close = this.close.bind(this);
this.state = {showModal: false};
}
open() {
this.setState({showModal: true});
}
close() {
this.setState({showModal: false});
}
onFormSubmit(values){
const data = {...values};
}
render() {
return(
<div>
<div className="map-menuitem" onClick={this.open}>Interactive Map</div>
<div>
<Modal className="modal-container"
show={this.state.showModal}
onHide={this.close}
animation={true}
dialogClassName="custom-map-modal"
>
<Modal.Header closeButton>
<Modal.Title>Interactive Map</Modal.Title>
</Modal.Header>
<Modal.Body>
The body
</Modal.Body>
<Modal.Footer>
<Button className="button-theme" onClick={this.close}>Close</Button>
<Button className="button-theme button-theme-blue" type="submit">Save changes</Button>
</Modal.Footer>
</Modal>
</div>
</div>
);
}
}
export default InteractiveMap;
在文档中写到我可以为 Modal 提供我的自定义 css,所以我做了dialogClassName="custom-map-modal" where
.custom-map-modal{
width:100%;
}
上面的也行不通。
我想在这里实现全屏Modal,如何使用上述方法实现,或者如果有其他方法可以做到,但我只想使用Bootstrap。
【问题讨论】:
-
必须与页面上的其他样式有关。通过将
width: 100%; height: 100%; margin:0和height: 100%;添加到modal-content,我能够制作您提供的全屏模式示例模式。首先查看 modals 父级,然后从那里向上工作,直到找到哪个父级阻止宽度全屏。 -
@ChaseDeAnda 是的,我可以通过覆盖默认的
modal, modal-footer, modal-content, modal-dialogcss 类来使其工作,但我最终会覆盖我不想要的其他页面的模式...... -
来自 Qi W 的回答从这个线程 stackoverflow.com/questions/32624634/… 为我工作。如果有人偶然发现此线程,只需添加即可。
标签: javascript twitter-bootstrap reactjs modal-dialog bootstrap-modal