【问题标题】:React - Fullscreen Modal with BootstrapReact - 带 Bootstrap 的全屏模式
【发布时间】: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:0height: 100%; 添加到modal-content,我能够制作您提供的全屏模式示例模式。首先查看 modals 父级,然后从那里向上工作,直到找到哪个父级阻止宽度全屏。
  • @ChaseDeAnda 是的,我可以通过覆盖默认的 modal, modal-footer, modal-content, modal-dialog css 类来使其工作,但我最终会覆盖我不想要的其他页面的模式......
  • 来自 Qi W 的回答从这个线程 stackoverflow.com/questions/32624634/… 为我工作。如果有人偶然发现此线程,只需添加即可。

标签: javascript twitter-bootstrap reactjs modal-dialog bootstrap-modal


【解决方案1】:

将 CSS 类放在 JSX 用来为组件分配 CSS 属性的属性“className”中。

看看这个例子: https://www.webpackbin.com/bins/-Kn1AnYrAFxOONefi_4N

 <Modal className="modal-container custom-map-modal"
      show={this.state.showModal}
      onHide={this.toggleState}
      animation={true}
      >

SASS 实现

.custom-map-modal {
   .modal-dialog {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
  }
  .modal-content {
    height: auto;
    min-height: 100%;
    border-radius: 0;
 }
}

【讨论】:

  • 感谢您的回答,但它似乎对我不起作用,它仍然显示默认模态.. 虽然它很简单,但我还缺少什么吗?
  • 看看上次更新我错过了示例中的一些 CSS。实施此解决方案。 stackoverflow.com/questions/18432394/…
猜你喜欢
  • 1970-01-01
  • 2022-10-19
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
相关资源
最近更新 更多