2020-12-25 13:13:07 +08:00
|
|
|
---
|
|
|
|
order: 24
|
|
|
|
title:
|
|
|
|
zh-CN: 响应式 maxTagCount
|
|
|
|
en-US: Responsive maxTagCount
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
多选下通过响应式布局让选项自动收缩。该功能对性能有所消耗,不推荐在大表单场景下使用。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Auto collapse to tag with responsive case. Not recommend use in large form case since responsive calculation has a perf cost.
|
|
|
|
|
|
|
|
```tsx
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { SelectProps } from 'antd';
|
2020-12-25 13:13:07 +08:00
|
|
|
import { Select, Space } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useState } from 'react';
|
2020-12-25 13:13:07 +08:00
|
|
|
|
|
|
|
interface ItemProps {
|
|
|
|
label: string;
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options: ItemProps[] = [];
|
|
|
|
|
|
|
|
for (let i = 10; i < 36; i++) {
|
|
|
|
const value = i.toString(36) + i;
|
|
|
|
options.push({
|
|
|
|
label: `Long Label: ${value}`,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [value, setValue] = useState(['a10', 'c12', 'h17', 'j19', 'k20']);
|
2020-12-25 13:13:07 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const selectProps: SelectProps = {
|
|
|
|
mode: 'multiple',
|
2020-12-25 13:13:07 +08:00
|
|
|
style: { width: '100%' },
|
|
|
|
value,
|
|
|
|
options,
|
|
|
|
onChange: (newValue: string[]) => {
|
|
|
|
setValue(newValue);
|
|
|
|
},
|
|
|
|
placeholder: 'Select Item...',
|
2022-05-19 09:46:26 +08:00
|
|
|
maxTagCount: 'responsive',
|
2020-12-25 13:13:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Space direction="vertical" style={{ width: '100%' }}>
|
|
|
|
<Select {...selectProps} />
|
|
|
|
<Select {...selectProps} disabled />
|
|
|
|
</Space>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2020-12-25 13:13:07 +08:00
|
|
|
```
|