antd的Select组件设置允许不选中任何项
时间: 2023-11-09 22:07:42 浏览: 265
可以设置`allowClear`属性为`true`,这样就可以在Select组件中显示一个清除按钮,点击清除按钮后就可以将选中的项清除掉,从而不选中任何项。示例代码如下:
```jsx
import { Select } from 'antd';
const { Option } = Select;
function handleChange(value) {
console.log(`selected ${value}`);
}
function handleBlur() {
console.log('blur');
}
function handleFocus() {
console.log('focus');
}
<Select
showSearch
style={{ width: 200 }}
placeholder="Select a person"
optionFilterProp="children"
onChange={handleChange}
onFocus={handleFocus}
onBlur={handleBlur}
filterOption={(input, option) =>
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
allowClear //设置允许清除
>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="tom">Tom</Option>
</Select>
```
阅读全文