首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应-自举多模态

反应-自举多模态
EN

Stack Overflow用户
提问于 2016-01-28 11:43:38
回答 7查看 24.6K关注 0票数 8

我在我的项目中使用了反作用力引导。我需要打开多个对话框。有办法做到这一点吗?

注意:引导here是有答案的,但是它在react引导中不起作用。谢谢。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2018-06-22 14:07:02

我们只是通过在不同的id中传递一次,然后将“show”状态设置为“显示”状态来处理多个modals:

mob/src/App.js#L26

代码语言:javascript
运行
复制
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 ...
票数 5
EN

Stack Overflow用户

发布于 2020-07-13 06:46:01

如果您使用scss作为css预处理程序,那么您可以使用一个循环来定义正确的z-index,以便使所有内容都显示为另一个顶部。

此循环最多处理5个级别,如果需要,可以增加数目。

代码语言:javascript
运行
复制
@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调制解调器使用的通用类名,请反复检查背景和主调制解调器是如何创建的。

票数 13
EN

Stack Overflow用户

发布于 2021-10-25 08:16:23

“第n种”解决方案对我不起作用。相反,我用这样的“最后一个孩子”来解决这个问题。

代码语言:javascript
运行
复制
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个级别上工作,但您可以根据需要添加其中的两个样式。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35060594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档