gpt4 book ai didi

reactjs - react 选择:禁用下拉列表

转载 作者:行者123 更新时间:2023-12-05 09:08:21 24 4
gpt4 key购买 nike

有没有办法禁用下拉列表?我没有找到任何可以帮助我的 Prop 。

特别是,当用户选择了超过 5 个元素时,我想禁用下拉列表。

我创建了 this codesandbox .它实际上不起作用,因为它没有链接到状态:

const limit = 3;
const defaults = [colourOptions[2], colourOptions[3]];

export default () => (
<Select
defaultValue={defaults}
isMulti
name="colors"
options={colourOptions}
className="basic-multi-select"
classNamePrefix="select"
isSearchable={defaults.length < limit}
// disableDropdown={defaults.length > limit} // <-- something like this
/>
)

最佳答案

您可以通过删除组件来“禁用/删除”下拉列表;

components={{
Menu: () => null, // Remove menu
MenuList: () => null, // Remove menu list
DropdownIndicator: () => null, // Remove dropdown icon
IndicatorSeparator: () => null // Remove separator
}}
<Select
defaultValue={defaults}
isMulti
name="colors"
options={colourOptions}
className="basic-multi-select"
classNamePrefix="select"
isSearchable={defaults.length < limit}
components={{
Menu: () => null,
MenuList: () => null,
DropdownIndicator: () => null,
IndicatorSeparator: () => null
}}
/>

Updated code-sandbox

Documentation

关于reactjs - react 选择:禁用下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63598117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com