[英]Dropdown menu flip position issue. React-Select + Material-UI Popper
I use the example autocomplete field from the Material-UI lib documentation.我使用 Material-UI lib 文档中的示例自动完成字段。 ( https://material-ui.com/demos/autocomplete/#react-select )
( https://material-ui.com/demos/autocomplete/#react-select )
There is a problem with fliping the menu when it opens at the bottom of the page or the browser's viewport.在页面底部或浏览器的视口打开菜单时,翻转菜单会出现问题。
Is there a way to fix this problem with Material-UI and react-select?有没有办法用 Material-UI 和 react-select 解决这个问题? Or do I need to write something custom?
还是我需要写一些自定义的东西?
If you are not using a <Menu/>
custom component, you can use the menuPlacement="auto"
prop of <Select/>
, then your problem is solved.如果您没有使用
<Menu/>
自定义组件,您可以使用<Select/>
的menuPlacement="auto"
,那么您的问题就解决了。
const components = {
Control,
// Menu , <-- delete it
NoOptionsMessage,
Option,
Placeholder,
SingleValue,
ValueContainer
};
https://github.com/JedWatson/react-select/issues/403 https://github.com/JedWatson/react-select/issues/403
Otherwise you can choose another selector, material-ui provides 2 more differents integration with the <Popper/>
component: react-autosuggest and downshift.否则你可以选择另一个选择器,material-ui 提供了 2 个不同的与
<Popper/>
组件的集成:react-autosuggest 和 downshift。
https://material-ui.com/demos/autocomplete/ https://material-ui.com/demos/autocomplete/
Hope it helps!希望能帮助到你!
i've faced the same problem, for <Select />
component i have used what TomLgls suggest, but for <AsyncSelect />
as a work-around, i used some offset calculations in my component :我遇到了同样的问题,对于
<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
}
/>
i hope it helps as well我希望它也有帮助
If you have created customMenu component then in that give className as open-menu-top and write this code for class:如果您创建了 customMenu 组件,则在其中将 className 作为 open-menu-top 并为类编写以下代码:
.menu-open-top { top: auto; bottom: 100%; }
Your CustomMenu maybe look like this:您的 CustomMenu 可能如下所示:
const CustomMenu = ({ children, innerProps, innerRef, selectProps }) => { return ( <div ref={innerRef} {...innerProps} className={`rs-menu ${customMenuClass} open-menu-top`} > {Your Logic} </div> ); };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.