reactjs - react-select 改变菜单高度
问题描述
有没有办法增加菜单高度?maxMenuHeight
我可以用属性降低菜单的高度。但我找不到增加它的高度的方法。我什至尝试过minMenuHeight
财产,但这并不能解决问题。这是我的代码以及自定义样式:
const defaultStyles = {
control: (base, state) => ({
...base,
}),
menu: base => ({
...base,
}),
menuList: base => ({
...base,
})
}
const customStyles = {
control: (base, state) => ({
...base,
background: "#000000",
// match with the menu
borderRadius: state.isFocused ? "3px 3px 0 0" : 3,
// Overwrittes the different states of border
// Removes weird border around container
boxShadow: state.isFocused ? null : null,
}),
menu: base => ({
...base,
// override border radius to match the box
borderRadius: 0,
backgroundColor: 'black',
// kill the gap
marginTop: 0
}),
menuList: base => ({
...base,
// kill the white space on first and last option
padding: 0
})
}
<AsyncSelect
className="basic-single"
classNamePrefix="select"
loadOptions={loadOptions}
maxMenuHeight={500}
isMulti
styles={localStorage.getItem('theme') === 'dark' ? customStyles : defaultStyles}
cacheOptions
onChange={(e) => setSelect(e)}
defaultOptions />
解决方案
你可以用样式来做到这一点。
更改
menuList: base => ({
...base,
})
和
menuList: base => ({
...base,
minHeight: "300px" // your desired height
})
在CodeSandbox工作演示。
推荐阅读
- jquery - 无法将 Json 数据加载到下拉列表
- nginx - 在谷歌入口控制器中建立 https 后 websocket 连接失败
- javascript - 导航悬停效果wordpress
- cmake - 如何根据生成器表达式 CONFIG 而不是 CMAKE_BUILD_TYPE 添加_子目录?
- reactjs - react-dates,当用户点击结束日期对应的输入字段时,应该显示结束日期对应的月份
- mongodb - 在不聚合的查找查询中获取 Mongo _id 作为字符串而不是 ObjectId
- java - 404 未找到 Tomcat 的 Spring Boot 战争
- c# - MVC 获取异常指定的强制转换无效
- mysql - SQL将doublon ID行合并为具有更多列的唯一行
- c# - 将数据(复杂数据/原始数据)发送到服务并获取响应(复杂数据/原始数据)的最佳方式(WCF 或 WEB API)