javascript - 使用带有复选框的 ExpansionPanelDetails 响应 js 模式

标签 javascript reactjs modal-dialog material-ui react-bootstrap

这就是我想要达到的效果:

enter image description here

这是我得到的效果:

enter image description here

正如您从图像中看到的,两个复选框位于 ExpansionPanelDetails 和模式内容之外。

特别考虑当内容需要调整大小时。

我尝试使用@material-ui/core中的Grid,我尝试使用react-bootstrap的Col,但我找不到解决方案。

链接:codesandbox

代码模式:

import React from "react";
import { Modal } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.css";

import {
  Checkbox,
  Divider,
  FormControl,
  FormControlLabel,
  FormGroup,
  FormLabel,
  Grid,
  Typography
} from "@material-ui/core";

import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";
import ExpansionPanel from "@material-ui/core/ExpansionPanel";
import ExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";

export default class CreateUserModal extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      expanded: true
    };
  }

  handleChange = panel => (event, isExpanded) => {
    this.setState({ expanded: isExpanded ? true : false });
  };

  checklist = () => {
    const { scopesList } = this.props;
    return scopesList.map((scope, i) => {
      let createChecked = true;
      let readChecked = true;
      let updateChecked = true;
      let deleteChecked = true;
      return (
        <Grid item xs={12} sm={12} xl={6} md={6} key={i}>
          <FormControl component="fieldset" fullWidth margin={"dense"}>
            <FormLabel component="label">
              <Typography>{scope}</Typography>
            </FormLabel>
            <FormGroup>
              <FormControlLabel
                control={
                  <Checkbox
                    color={"primary"}
                    checked={createChecked}
                    onChange={evt => this.onChangeScope(scope, "create", evt)}
                  />
                }
                label="Create"
              />
              <FormControlLabel
                control={
                  <Checkbox
                    color={"primary"}
                    checked={readChecked}
                    onChange={evt => this.onChangeScope(scope, "read", evt)}
                  />
                }
                label="Read"
              />
              <FormControlLabel
                control={
                  <Checkbox
                    color={"primary"}
                    checked={updateChecked}
                    onChange={evt => this.onChangeScope(scope, "update", evt)}
                  />
                }
                label="Update"
              />
              <FormControlLabel
                control={
                  <Checkbox
                    color={"primary"}
                    checked={deleteChecked}
                    onChange={evt => this.onChangeScope(scope, "delete", evt)}
                  />
                }
                label="Delete"
              />
            </FormGroup>
          </FormControl>
          <Divider />
        </Grid>
      );
    });
  };

  render() {
    const { expanded } = this.state;
    const { show, onHide } = this.props;

    return (
      <Modal
        show={show}
        onHide={onHide}
        size="xl"
        aria-labelledby="contained-modal-title-vcenter"
        centered
      >
        <Modal.Header closeButton>
          <Modal.Title
            style={{
              width: "100%",
              display: "flex",
              justifyContent: "center"
            }}
          >
            Add New
          </Modal.Title>
        </Modal.Header>
        <Modal.Body>
          <ExpansionPanel
            expanded={expanded === true}
            onChange={this.handleChange("panel")}
          >
            <ExpansionPanelSummary
              expandIcon={<ExpandMoreIcon />}
              aria-controls="panel1bh-content"
              id="panel1bh-header"
            >
              <Typography>Scopes</Typography>
            </ExpansionPanelSummary>
            <ExpansionPanelDetails>{this.checklist()}</ExpansionPanelDetails>
          </ExpansionPanel>
        </Modal.Body>
        <Modal.Footer>Footer</Modal.Footer>
      </Modal>
    );
  }
}

你能给我一些建议吗?

最佳答案

您应该添加row类(class) <ExpansionPanelDetails> result

关于javascript - 使用带有复选框的 ExpansionPanelDetails 响应 js 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57856719/

相关文章:

angularjs - 如何在 Angular JS 中向 ng-dialog 添加标题、消息、按钮,就像我们在 JQuery 提示符中所做的那样

javascript - <链接 rel ="stylesheet"类型 ="text/css"href ="../styles.css"> 不工作

javascript - 为什么即使我的互联网连接不起作用,navigator.onLine() 也会返回 true?

javascript - VueRouter 在业力单元测试中未定义

javascript - React组件导入静态json文件

jQuery UI 对话框顶部间距

javascript - 如何使用timezone-js?

javascript - 在光标处插入 react

reactjs - 将组件渲染为 prop 的问题

javascript - 从远程页面关闭jQuery模式对话框