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

97 lines
2.2 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
2018-05-21 17:07:39 +08:00
order: 3
2017-03-24 12:14:00 +08:00
title:
2016-07-10 08:55:43 +08:00
zh-CN: 三种大小
2017-03-24 12:14:00 +08:00
en-US: Sizes
2016-03-31 09:40:55 +08:00
---
2015-08-08 19:11:10 +08:00
2016-07-10 08:55:43 +08:00
## zh-CN
三种大小的选择框,当 size 分别为 `large``small` 时,输入框高度为 `40px``24px` ,默认高度为 `32px`
2015-08-08 19:11:10 +08:00
2016-07-10 08:55:43 +08:00
## en-US
2017-10-20 15:47:42 +08:00
The height of the input field for the select defaults to 32px. If size is set to large, the height will be 40px, and if set to small, 24px.
2016-07-10 08:55:43 +08:00
```tsx
2022-05-23 14:37:16 +08:00
import { Radio, Select } from 'antd';
import type { SizeType } from 'antd/es/config-provider/SizeContext';
import React, { useState } from 'react';
import type { SelectProps, RadioChangeEvent } from 'antd';
2018-06-27 15:55:04 +08:00
const options: SelectProps['options'] = [];
2017-03-24 12:14:00 +08:00
for (let i = 10; i < 36; i++) {
options.push({
value: i.toString(36) + i,
label: i.toString(36) + i,
});
2017-03-24 12:14:00 +08:00
}
const handleChange = (value: string | string[]) => {
2017-03-24 12:14:00 +08:00
console.log(`Selected: ${value}`);
};
2017-03-24 12:14:00 +08:00
const App: React.FC = () => {
const [size, setSize] = useState<SizeType>('middle');
2017-03-24 12:14:00 +08:00
const handleSizeChange = (e: RadioChangeEvent) => {
setSize(e.target.value);
2019-05-07 14:57:32 +08:00
};
2017-03-24 12:14:00 +08:00
return (
<>
<Radio.Group value={size} onChange={handleSizeChange}>
<Radio.Button value="large">Large</Radio.Button>
<Radio.Button value="default">Default</Radio.Button>
<Radio.Button value="small">Small</Radio.Button>
</Radio.Group>
<br />
<br />
<Select
size={size}
defaultValue="a1"
onChange={handleChange}
style={{ width: 200 }}
options={options}
/>
<br />
<Select
mode="multiple"
size={size}
placeholder="Please select"
defaultValue={['a10', 'c12']}
onChange={handleChange}
style={{ width: '100%' }}
options={options}
/>
<br />
<Select
mode="tags"
size={size}
placeholder="Please select"
defaultValue={['a10', 'c12']}
onChange={handleChange}
style={{ width: '100%' }}
options={options}
/>
</>
);
};
2015-08-08 19:11:10 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```
2015-08-08 19:11:10 +08:00
2019-05-07 14:57:32 +08:00
```css
.code-box-demo .ant-select {
2015-10-22 21:12:13 +08:00
margin: 0 8px 10px 0;
2015-08-08 19:11:10 +08:00
}
2016-05-13 11:45:09 +08:00
2020-05-10 22:11:09 +08:00
.ant-row-rtl .code-box-demo .ant-select {
margin: 0 0 10px 8px;
}
2016-05-13 11:45:09 +08:00
#components-select-demo-search-box .code-box-demo .ant-select {
margin: 0;
}
2019-05-07 14:57:32 +08:00
```