mar*_*lle 2 reactjs react-select
有没有办法禁用下拉列表?我没有找到任何可以帮助我的道具。
特别是,当用户选择超过 5 个元素时,我想禁用下拉列表。
我创建了这个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
/>
)
Run Code Online (Sandbox Code Playgroud)
您可以通过删除组件来“禁用/删除”下拉菜单;
components={{
Menu: () => null, // Remove menu
MenuList: () => null, // Remove menu list
DropdownIndicator: () => null, // Remove dropdown icon
IndicatorSeparator: () => null // Remove separator
}}
Run Code Online (Sandbox Code Playgroud)
<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
}}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7624 次 |
| 最近记录: |