日期范围选择器组件无法在模态内工作
Date Range Picker component not working inside a modal
我也在尝试使用 rsuite daterangepicker 组件和 antd 的 daterangepicker 但是当我尝试在 React 中使用它们时 Material UI Dialog/Modal 选择日期的弹出窗口不会' t 显示或者它显示在模态之外,如下所示:
Click Here to check the Image
我该如何解决这个问题?
检查问题的代码:
import React, { useState, useEffect } from "react";
import Dialog from "@material-ui/core/Dialog";
import MuiDialogTitle from "@material-ui/core/DialogTitle";
import MuiDialogContent from "@material-ui/core/DialogContent";
import MuiDialogActions from "@material-ui/core/DialogActions";
import { DateRangePicker } from "rsuite";
export default function CustomizedDialogs(props) {
const [open, setOpen] = useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
setStart(null);
setEnd(null);
setSelected(false);
};
return(
<div>
<Dialog
maxWidth={"xl"}
onClose={handleClose}
aria-labelledby="customized-dialog-title"
open={open}
>
<DialogTitle
id="customized-dialog-title"
onClose={handleClose}
>
Name
</DialogTitle>
<DialogContent dividers>
<div>
<DateRangePicker
appearance="default"
placeholder="Select range"
/>
</div>
</DialogContent>
</Dialog>
</div>
}
这似乎只是 CSS 的问题。
检查工作 sample on codesandbox 的 link
仅更改了 daterangepicker div 的 z-index,使其大于 Modal 的 z-index。
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import MuiDialogTitle from "@material-ui/core/DialogTitle";
import MuiDialogContent from "@material-ui/core/DialogContent";
import MuiDialogActions from "@material-ui/core/DialogActions";
import IconButton from "@material-ui/core/IconButton";
import CloseIcon from "@material-ui/icons/Close";
import Typography from "@material-ui/core/Typography";
import { DateRangePicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";
import "./styles.css";
const styles = (theme) => ({
root: {
margin: 0,
padding: theme.spacing(2)
},
closeButton: {
position: "absolute",
right: theme.spacing(1),
top: theme.spacing(1),
color: theme.palette.grey[500]
}
});
const DialogTitle = withStyles(styles)((props) => {
const { children, classes, onClose, ...other } = props;
return (
<MuiDialogTitle disableTypography className={classes.root} {...other}>
<Typography variant="h6">{children}</Typography>
{onClose ? (
<IconButton
aria-label="close"
className={classes.closeButton}
onClick={onClose}
>
<CloseIcon />
</IconButton>
) : null}
</MuiDialogTitle>
);
});
const DialogContent = withStyles((theme) => ({
root: {
padding: theme.spacing(2)
}
}))(MuiDialogContent);
const DialogActions = withStyles((theme) => ({
root: {
margin: 0,
padding: theme.spacing(1)
}
}))(MuiDialogActions);
export default function CustomizedDialogs() {
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open dialog
</Button>
<Dialog
onClose={handleClose}
aria-labelledby="customized-dialog-title"
open={open}
>
<DialogTitle id="customized-dialog-title" onClose={handleClose}>
Modal title
</DialogTitle>
<DialogContent dividers>
<DateRangePicker appearance="default" placeholder="Select range" />
<Typography gutterBottom>
Cras mattis consectetur purus sit amet fermentum. Cras justo odio,
dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta
ac consectetur ac, vestibulum at eros.
</Typography>
<Typography gutterBottom>
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor
auctor.
</Typography>
<Typography gutterBottom>
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo
cursus magna, vel scelerisque nisl consectetur et. Donec sed odio
dui. Donec ullamcorper nulla non metus auctor fringilla.
</Typography>
</DialogContent>
<DialogActions>
<Button autoFocus onClick={handleClose} color="primary">
Save changes
</Button>
</DialogActions>
</Dialog>
</div>
);
}
和 CSS 文件
.App {
font-family: sans-serif;
text-align: center;
}
.rs-picker-daterange-menu {
z-index: 10000000000; /* added a large random number, you can choose it more carefully based on your use-case.*/
}
我也在尝试使用 rsuite daterangepicker 组件和 antd 的 daterangepicker 但是当我尝试在 React 中使用它们时 Material UI Dialog/Modal 选择日期的弹出窗口不会' t 显示或者它显示在模态之外,如下所示:
Click Here to check the Image
我该如何解决这个问题?
检查问题的代码:
import React, { useState, useEffect } from "react";
import Dialog from "@material-ui/core/Dialog";
import MuiDialogTitle from "@material-ui/core/DialogTitle";
import MuiDialogContent from "@material-ui/core/DialogContent";
import MuiDialogActions from "@material-ui/core/DialogActions";
import { DateRangePicker } from "rsuite";
export default function CustomizedDialogs(props) {
const [open, setOpen] = useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
setStart(null);
setEnd(null);
setSelected(false);
};
return(
<div>
<Dialog
maxWidth={"xl"}
onClose={handleClose}
aria-labelledby="customized-dialog-title"
open={open}
>
<DialogTitle
id="customized-dialog-title"
onClose={handleClose}
>
Name
</DialogTitle>
<DialogContent dividers>
<div>
<DateRangePicker
appearance="default"
placeholder="Select range"
/>
</div>
</DialogContent>
</Dialog>
</div>
}
这似乎只是 CSS 的问题。 检查工作 sample on codesandbox 的 link 仅更改了 daterangepicker div 的 z-index,使其大于 Modal 的 z-index。
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import MuiDialogTitle from "@material-ui/core/DialogTitle";
import MuiDialogContent from "@material-ui/core/DialogContent";
import MuiDialogActions from "@material-ui/core/DialogActions";
import IconButton from "@material-ui/core/IconButton";
import CloseIcon from "@material-ui/icons/Close";
import Typography from "@material-ui/core/Typography";
import { DateRangePicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";
import "./styles.css";
const styles = (theme) => ({
root: {
margin: 0,
padding: theme.spacing(2)
},
closeButton: {
position: "absolute",
right: theme.spacing(1),
top: theme.spacing(1),
color: theme.palette.grey[500]
}
});
const DialogTitle = withStyles(styles)((props) => {
const { children, classes, onClose, ...other } = props;
return (
<MuiDialogTitle disableTypography className={classes.root} {...other}>
<Typography variant="h6">{children}</Typography>
{onClose ? (
<IconButton
aria-label="close"
className={classes.closeButton}
onClick={onClose}
>
<CloseIcon />
</IconButton>
) : null}
</MuiDialogTitle>
);
});
const DialogContent = withStyles((theme) => ({
root: {
padding: theme.spacing(2)
}
}))(MuiDialogContent);
const DialogActions = withStyles((theme) => ({
root: {
margin: 0,
padding: theme.spacing(1)
}
}))(MuiDialogActions);
export default function CustomizedDialogs() {
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open dialog
</Button>
<Dialog
onClose={handleClose}
aria-labelledby="customized-dialog-title"
open={open}
>
<DialogTitle id="customized-dialog-title" onClose={handleClose}>
Modal title
</DialogTitle>
<DialogContent dividers>
<DateRangePicker appearance="default" placeholder="Select range" />
<Typography gutterBottom>
Cras mattis consectetur purus sit amet fermentum. Cras justo odio,
dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta
ac consectetur ac, vestibulum at eros.
</Typography>
<Typography gutterBottom>
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor
auctor.
</Typography>
<Typography gutterBottom>
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo
cursus magna, vel scelerisque nisl consectetur et. Donec sed odio
dui. Donec ullamcorper nulla non metus auctor fringilla.
</Typography>
</DialogContent>
<DialogActions>
<Button autoFocus onClick={handleClose} color="primary">
Save changes
</Button>
</DialogActions>
</Dialog>
</div>
);
}
和 CSS 文件
.App {
font-family: sans-serif;
text-align: center;
}
.rs-picker-daterange-menu {
z-index: 10000000000; /* added a large random number, you can choose it more carefully based on your use-case.*/
}