gpt4 book ai didi

reactjs - React 日期选择器隐藏在溢出父项后面(弹出窗口固定放置问题)

转载 作者:行者123 更新时间:2023-12-03 23:33:51 31 4
gpt4 key购买 nike

我正在尝试从 react datepicker 中弹出日期选择弹出框以从 Material UI 菜单项中打开。
我已将我的菜单项设为 react datepicker 输入字段。问题是我的输入字段是选择日期弹出框的 anchor ,弹出框在我的菜单中打开。我希望弹出窗口在菜单上方打开。
react datepicker 文档没有很多关于弹出框位置的信息。知道如何实现吗?
here is a screenshot of the unwanted behavior with the popover being "trapped" in the menu
快速浏览我的菜单代码:

// this icon is the anchor for the menu
<MoreIcon onClick={handleClick} />
<Menu
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
//this is my Date picker component
<Reschedule handleReschedule={handleReschedule} />
</Menu>
和我的日期选择器组件(使用自定义输入字段作为菜单项):
export const Reschedule = ({ handleReschedule }) => {
// ref to the datePicker to control open/close
const calendar = createRef();

//to Open the date picker
const openDatepicker = (e) => {
calendar.current.setOpen(true);
};
//to close the date picker
const closeDatepicker = (e) => {
calendar.current.setOpen(false);
};

const RescheduleButton = ({ onClick }) => {
return (
<MenuItem
className="overdue__rescheduleButton"
onClick={() => {
onClick();
}}
>
Reschedule
</MenuItem>
);
};

return (
<DatePicker
selected={null}
onChange={(date) => {
handleReschedule(date);
}}
ref={calendar}
minDate={subDays(new Date(), 0)}
customInput={<RescheduleButton onClick={openDatepicker} />}
popperPlacement="bottom-end"
/>
);
};
提前致谢

最佳答案

在撰写本文时,此 Prop 尚未记录,但您可以使用 popperProps配置 popper 属性 - 他们使用 Popper.js .在您的情况下使用 positionFixed: true使其相对于视口(viewport)的初始包含 block (即 <html> )

<DatePicker
popperProps={{
positionFixed: true // use this to make the popper position: fixed
}}
/>
Edit eloquent-dream-jxlzp
https://github.com/Hacker0x01/react-datepicker/blob/master/src/popper_component.jsx

关于reactjs - React 日期选择器隐藏在溢出父项后面(弹出窗口固定放置问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64254322/

31 4 0
文章推荐: html - 如何使
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com