2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 1
|
2016-10-09 22:55:50 +08:00
|
|
|
title:
|
2016-07-10 08:55:43 +08:00
|
|
|
zh-CN: 带搜索框
|
|
|
|
en-US: Select with search field
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-16 14:54:31 +08:00
|
|
|
|
2016-07-10 08:55:43 +08:00
|
|
|
## zh-CN
|
2016-10-09 22:55:50 +08:00
|
|
|
|
2016-04-27 18:07:48 +08:00
|
|
|
展开后可对选项进行搜索。
|
2015-06-16 14:54:31 +08:00
|
|
|
|
2016-07-10 08:55:43 +08:00
|
|
|
## en-US
|
2016-10-09 22:55:50 +08:00
|
|
|
|
2016-07-10 08:55:43 +08:00
|
|
|
Search the options while expanded.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Select } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React from 'react';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-27 21:32:45 +08:00
|
|
|
const { Option } = Select;
|
2015-06-16 14:54:31 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (value: string) => {
|
2016-02-17 18:04:42 +08:00
|
|
|
console.log(`selected ${value}`);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2015-06-16 14:54:31 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onSearch = (value: string) => {
|
|
|
|
console.log('search:', value);
|
|
|
|
};
|
2019-04-22 21:42:09 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2016-10-09 22:55:50 +08:00
|
|
|
<Select
|
|
|
|
showSearch
|
2016-09-12 10:09:22 +08:00
|
|
|
placeholder="Select a person"
|
2016-02-23 11:16:58 +08:00
|
|
|
optionFilterProp="children"
|
2019-04-22 21:42:09 +08:00
|
|
|
onChange={onChange}
|
|
|
|
onSearch={onSearch}
|
2019-05-07 14:57:32 +08:00
|
|
|
filterOption={(input, option) =>
|
2022-05-19 09:46:26 +08:00
|
|
|
(option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
|
2019-05-07 14:57:32 +08:00
|
|
|
}
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2016-09-12 10:09:22 +08:00
|
|
|
<Option value="jack">Jack</Option>
|
|
|
|
<Option value="lucy">Lucy</Option>
|
|
|
|
<Option value="tom">Tom</Option>
|
2022-04-03 23:27:45 +08:00
|
|
|
</Select>
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|