我在我的项目中使用了反作用力引导。我需要打开多个对话框。有办法做到这一点吗?
注意:引导here是有答案的,但是它在react引导中不起作用。谢谢。
发布于 2018-06-22 14:07:02
我们只是通过在不同的id中传递一次,然后将“show”状态设置为“显示”状态来处理多个modals:
class App extends Component {
constructor(props, context) {
super(props, context);
this.handleShow = this.handleShow.bind(this);
this.handleClose = this.handleClose.bind(this);
this.state = {
show: null
};
}
handleClose() {
this.setState({show: id});
}
handleShow(id) {
this.setState({show: id});
}
render() {
return (
<div className="App">
<Grid>
<Row>
<Col xsOffset={1} sm={5}>
<Button bsStyle="primary" bsSize="large" onClick={() => this.handleShow('here')}>
<h1>You are here!</h1>
</Button>
<Modal
show={this.state.show == 'here'} onHide={this.handleClose}
>
<Modal.Header closeButton closeLabel="close window">
</Modal.Header>
<Modal.Body>
<p className='landing-page-markers you-are-here'>Tired of toy projects, tutorials and online courses?
<img src={logo} className="App-logo" alt="logo" />
</p>
</Modal.Body>
</Modal>
</Col>
</Row>
... more modals passing in different ids ...
发布于 2020-07-13 06:46:01
如果您使用scss作为css预处理程序,那么您可以使用一个循环来定义正确的z-index
,以便使所有内容都显示为另一个顶部。
此循环最多处理5个级别,如果需要,可以增加数目。
@for $i from 1 through 6 {
$zIndexBackdrop: #{1000 + (5 * $i)};
$zIndexContent: #{1000 + (5 * $i) + 2};
.modal-backdrop.show:nth-of-type(#{$i}) {
z-index: $zIndexBackdrop;
}
div[role="dialog"][aria-modal="true"]:nth-of-type(#{$i}) {
z-index: $zIndexContent;
}
}
这里的循环1 through 6
循环5次,如果你想通过增加数量来增加调制解调器的深度,你可以增加它的深度。
我使用了react-bootstrap
调制解调器使用的通用类名,请反复检查背景和主调制解调器是如何创建的。
发布于 2021-10-25 08:16:23
“第n种”解决方案对我不起作用。相反,我用这样的“最后一个孩子”来解决这个问题。
div[role="dialog"][aria-modal="true"]:nth-last-child(1) {
z-index: 1125;
}
.modal-backdrop.show:nth-last-child(2){
z-index: 1100;
}
div[role="dialog"][aria-modal="true"]:nth-last-child(3) {
z-index: 1075;
}
.modal-backdrop.show:nth-last-child(4){
z-index: 1050;
}
div[role="dialog"][aria-modal="true"]:nth-last-child(5) {
z-index: 1025;
}
.modal-backdrop.show:nth-last-child(6){
z-index: 1000;
}
其思想是,每次显示模态时,都会将一个模态元素和一个阴影元素附加到主体中(库已经这样做了)。因此,从最后一个子元素开始,(n + 1)元素将是一个模态元素,而(n + 2)元素将是模态阴影元素。
在这个示例中,我将嵌套的modals设置为最多在3个级别上工作,但您可以根据需要添加其中的两个样式。
https://stackoverflow.com/questions/35060594
复制相似问题