【问题标题】:Dropdown menu flip position issue. React-Select + Material-UI Popper下拉菜单翻转位置问题。 React-Select + Material-UI Popper
【发布时间】:2019-07-26 18:02:43
【问题描述】:
【问题讨论】:
标签:
reactjs
drop-down-menu
material-ui
flip
react-select
【解决方案2】:
我也遇到了同样的问题,对于 <Select /> 组件,我使用了 TomLgls 建议的方法,但对于 <AsyncSelect /> 作为解决方法,我在组件中使用了一些偏移计算:
const rootHeight = document.getElementById('root').offsetHeight ;
const selectElement = document.getElementById('async_select_container_id');
const selectOffsetBottom= selectElement.offsetHeight + selectElement.offsetTop;
...
<AsyncSelect
{...listProps}
menuPlacement={
rootHeight - selectOffsetBottom > 210 ? 'auto' : 'top' // react-select menu height is 200px in my case
}
/>
希望对你有帮助
【解决方案3】:
如果您创建了 customMenu 组件,那么在其中将 className 设置为 open-menu-top 并为 class 编写以下代码:
.menu-open-top {
top: auto;
bottom: 100%;
}
您的 CustomMenu 可能如下所示:
const CustomMenu = ({ children, innerProps, innerRef, selectProps }) => {
return (
<div
ref={innerRef}
{...innerProps}
className={`rs-menu ${customMenuClass} open-menu-top`}
>
{Your Logic}
</div>
);
};