ant-design/components/select/demo/search.md

57 lines
920 B
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 1
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-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-07-10 08:55:43 +08:00
Search the options while expanded.
```tsx
import { Select } from 'antd';
2022-05-23 14:37:16 +08:00
import React from 'react';
2018-06-27 15:55:04 +08:00
const onChange = (value: string) => {
console.log(`selected ${value}`);
};
2015-06-16 14:54:31 +08:00
const onSearch = (value: string) => {
console.log('search:', value);
};
const App: React.FC = () => (
<Select
showSearch
placeholder="Select a person"
optionFilterProp="children"
onChange={onChange}
onSearch={onSearch}
2019-05-07 14:57:32 +08:00
filterOption={(input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
2019-05-07 14:57:32 +08:00
}
options={[
{
value: 'jack',
label: 'Jack',
},
{
value: 'lucy',
label: 'Lucy',
},
{
value: 'tom',
label: 'Tom',
},
]}
/>
2018-11-28 15:00:03 +08:00
);
export default App;
2019-05-07 14:57:32 +08:00
```