ant-design/components/auto-complete/demo/certain-category.md

161 lines
3.4 KiB
Markdown
Raw Normal View History

---
order: 4
title:
zh-CN: 查询模式 - 确定类目
en-US: Lookup-Patterns - Certain Category
---
## zh-CN
[查询模式: 确定类目](https://ant.design/docs/spec/reaction#Lookup-Patterns) 示例。
## en-US
2019-05-07 14:57:32 +08:00
Demonstration of [Lookup Patterns: Certain Category](https://ant.design/docs/spec/reaction#Lookup-Patterns). Basic Usage, set datasource of autocomplete with `dataSource` property.
2019-05-07 14:57:32 +08:00
```jsx
use ant design icons 4.0 (#18217) * feat: use @ant-design/icons@4.0 * feat: use createFromIconfontCN to make site works * feat: update doc for Icon * feat: use icon in component Alert * feat: use icon in component Avatar * feat: use icon in component Breadcrumb * feat: use icon in component Button * feat: use icon in component Cascader * feat: use icon in component Collapse * feat: use icon in component Datepicker * feat: use icon in component Dropdown * feat: use icon in component Form * feat: use icon in component Input * feat: use icon in component InputNumber * feat: use icon in component Layout * feat: use icon in component Mention * feat: use icon in component Message * feat: use icon in component Modal * feat: use icon in component Notification * feat: use icon in component PageHeader * feat: use icon in component Pagination * feat: use icon in component Popconfirm * feat: use icon in component Progress * feat: use icon in component Rate * feat: use icon in component Result * feat: use icon in component Select * feat: use icon in component Step * feat: use icon in component Switch * feat: use icon in component Table * feat: use icon in component Tab * feat: use icon in component Tag * feat: handle rest component which using Icon * fix: remove unused vars * feat: use latest alpha ant design icons * fix: failed test in uploadlist.test.js * test: update snapshot for icons * doc: add Icon for site * doc: use @ant-design/icons in site * chore: use latest icons * fix: tslint issue * fix: test cases * fix: types for react * fix: lint rules for import orders * fix: use @ant-design/icons@4.0.0-alpha.5 to avoid insert css in server render * fix: eslint error in demo/**.md * inject antd icons * update snapshot * fix site * doc: update docs * fix: code snippets icon in site * feat: use latest @ant-design/icons * fix: icon props in message
2019-08-13 14:07:17 +08:00
import { Input, AutoComplete } from 'antd';
import { Search } from '@ant-design/icons';
2018-06-27 15:55:04 +08:00
const { Option, OptGroup } = AutoComplete;
2019-05-07 14:57:32 +08:00
const dataSource = [
{
2019-06-11 13:07:58 +08:00
title: 'Libraries',
2019-05-07 14:57:32 +08:00
children: [
{
title: 'AntDesign',
count: 10000,
},
{
title: 'AntDesign UI',
count: 10600,
},
],
},
{
2019-06-11 13:07:58 +08:00
title: 'Solutions',
2019-05-07 14:57:32 +08:00
children: [
{
2019-06-11 13:07:58 +08:00
title: 'AntDesign UI',
2019-05-07 14:57:32 +08:00
count: 60100,
},
{
2019-06-11 13:07:58 +08:00
title: 'AntDesign',
2019-05-07 14:57:32 +08:00
count: 30010,
},
],
},
{
2019-06-11 13:07:58 +08:00
title: 'Articles',
2019-05-07 14:57:32 +08:00
children: [
{
2019-06-11 13:07:58 +08:00
title: 'AntDesign design language',
2019-05-07 14:57:32 +08:00
count: 100000,
},
],
},
];
function renderTitle(title) {
2017-03-06 17:56:34 +08:00
return (
<span>
{title}
<a
style={{ float: 'right' }}
href="https://www.google.com/search?q=antd"
target="_blank"
rel="noopener noreferrer"
2019-05-07 14:57:32 +08:00
>
2019-06-11 13:07:58 +08:00
more
2017-03-06 17:56:34 +08:00
</a>
</span>
);
}
2019-05-07 14:57:32 +08:00
const options = dataSource
.map(group => (
<OptGroup key={group.title} label={renderTitle(group.title)}>
{group.children.map(opt => (
<Option key={opt.title} value={opt.title}>
{opt.title}
2019-06-11 13:07:58 +08:00
<span className="certain-search-item-count">{opt.count} people</span>
2019-05-07 14:57:32 +08:00
</Option>
))}
</OptGroup>
))
.concat([
<Option disabled key="all" className="show-all">
<a href="https://www.google.com/search?q=antd" target="_blank" rel="noopener noreferrer">
2019-06-11 13:07:58 +08:00
View all results
2019-05-07 14:57:32 +08:00
</a>
</Option>,
]);
function Complete() {
return (
<div className="certain-category-search-wrapper" style={{ width: 250 }}>
<AutoComplete
className="certain-category-search"
dropdownClassName="certain-category-search-dropdown"
dropdownMatchSelectWidth={false}
dropdownStyle={{ width: 300 }}
size="large"
style={{ width: '100%' }}
dataSource={options}
placeholder="input here"
optionLabelProp="value"
>
use ant design icons 4.0 (#18217) * feat: use @ant-design/icons@4.0 * feat: use createFromIconfontCN to make site works * feat: update doc for Icon * feat: use icon in component Alert * feat: use icon in component Avatar * feat: use icon in component Breadcrumb * feat: use icon in component Button * feat: use icon in component Cascader * feat: use icon in component Collapse * feat: use icon in component Datepicker * feat: use icon in component Dropdown * feat: use icon in component Form * feat: use icon in component Input * feat: use icon in component InputNumber * feat: use icon in component Layout * feat: use icon in component Mention * feat: use icon in component Message * feat: use icon in component Modal * feat: use icon in component Notification * feat: use icon in component PageHeader * feat: use icon in component Pagination * feat: use icon in component Popconfirm * feat: use icon in component Progress * feat: use icon in component Rate * feat: use icon in component Result * feat: use icon in component Select * feat: use icon in component Step * feat: use icon in component Switch * feat: use icon in component Table * feat: use icon in component Tab * feat: use icon in component Tag * feat: handle rest component which using Icon * fix: remove unused vars * feat: use latest alpha ant design icons * fix: failed test in uploadlist.test.js * test: update snapshot for icons * doc: add Icon for site * doc: use @ant-design/icons in site * chore: use latest icons * fix: tslint issue * fix: test cases * fix: types for react * fix: lint rules for import orders * fix: use @ant-design/icons@4.0.0-alpha.5 to avoid insert css in server render * fix: eslint error in demo/**.md * inject antd icons * update snapshot * fix site * doc: update docs * fix: code snippets icon in site * feat: use latest @ant-design/icons * fix: icon props in message
2019-08-13 14:07:17 +08:00
<Input suffix={<Search className="certain-category-icon" />} />
</AutoComplete>
</div>
);
}
ReactDOM.render(<Complete />, mountNode);
2019-05-07 14:57:32 +08:00
```
2019-05-07 14:57:32 +08:00
```css
.certain-category-search.ant-select-auto-complete .ant-input-affix-wrapper .ant-input-suffix {
2017-03-06 17:56:34 +08:00
right: 12px;
}
.certain-category-search-dropdown .ant-select-dropdown-menu-item-group-title {
color: #666;
font-weight: bold;
}
.certain-category-search-dropdown .ant-select-dropdown-menu-item-group {
2019-05-07 14:57:32 +08:00
border-bottom: 1px solid #f6f6f6;
}
.certain-category-search-dropdown .ant-select-dropdown-menu-item {
padding-left: 16px;
}
.certain-category-search-dropdown .ant-select-dropdown-menu-item.show-all {
text-align: center;
cursor: default;
}
.certain-category-search-dropdown .ant-select-dropdown-menu {
max-height: 300px;
}
.certain-search-item-count {
2019-05-07 14:57:32 +08:00
position: absolute;
color: #999;
right: 16px;
}
.certain-category-search.ant-select-focused .certain-category-icon {
2017-03-06 17:56:34 +08:00
color: #108ee9;
}
.certain-category-icon {
2019-05-07 14:57:32 +08:00
color: #6e6e6e;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
font-size: 16px;
}
2019-05-07 14:57:32 +08:00
```