ant-design/components/select/demo/search-sort.md
黑雨 91821d4d3a
feat: select edit demo to data driven (#37601)
* feat: select edit demo to data driven

* feat: edit demo to data driven

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2022-09-19 18:01:16 +08:00

1.0 KiB

order title
4
zh-CN en-US
带排序的搜索 Search with sort

zh-CN

在搜索模式下对过滤结果项进行排序。

en-US

Search the options with sorting.

import { Select } from 'antd';
import React from 'react';

const App: React.FC = () => (
  <Select
    showSearch
    style={{ width: 200 }}
    placeholder="Search to Select"
    optionFilterProp="children"
    filterOption={(input, option) => (option?.label ?? '').includes(input)}
    filterSort={(optionA, optionB) =>
      (optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
    }
    options={[
      {
        value: '1',
        label: 'Not Identified',
      },
      {
        value: '2',
        label: 'Closed',
      },
      {
        value: '3',
        label: 'Communicated',
      },
      {
        value: '4',
        label: 'Identified',
      },
      {
        value: '5',
        label: 'Resolved',
      },
      {
        value: '6',
        label: 'Cancelled',
      },
    ]}
  />
);

export default App;