提问人:Rohit Verma 提问时间:9/26/2023 最后编辑:halferRohit Verma 更新时间:10/8/2023 访问量:87
如何使用react-select解决react-window高度问题?[关闭]
How to fix react-window height issue with react-select? [closed]
问:
我正在将react-select与react-window一起使用,但是下拉列表的高度存在问题,例如:
我只有两个值,但高度大于项目,我该如何解决?来自 API 的下拉列表值可能会有所不同。
注意:我还需要定义下拉列表的maxHeight。
答:
1赞
Sarkar
9/26/2023
#1
使用 react 样式更改高度以解决此处的问题max-content
<List
style={{ height: "max-content", maxHeight: maxHeight }}
height={1}
itemCount={children.length}
itemSize={itemHeight}
initialScrollOffset={initialOffset}
>
{({ index, style }) => <div style={style}>{children[index]}</div>}
</List>
您仍然需要指定,因为组件需要它,但它可以是任何值,将覆盖它。这是问题的修复分支height
max-content
评论
0赞
Rohit Verma
9/26/2023
我还需要定义下拉列表的 maxHeight。
0赞
Sarkar
9/26/2023
@RohitVerma我已经更新了答案和分叉,现在它也包括 maxHeight。
0赞
Rohit Verma
9/26/2023
如果下拉项将超过其给出问题的 2-3 个,您能否检查 codSandbox 再次,我在问题中给出的 codeSanbox 链接中实现了您的更改。
1赞
Rohit Verma
9/26/2023
感谢@Sarkar它现在工作正常,我用解决方案更新了我的代码沙盒......
0赞
Rohit Verma
10/3/2023
我们可以让 itemSize 自动吗?因为当大数据时,项目内容是重叠的......在下拉选项中...
评论