mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
d4d79bbe13
* fix: Select style sync with v3 * update demo * update test case
76 lines
1.5 KiB
Markdown
76 lines
1.5 KiB
Markdown
---
|
|
order: 4
|
|
title:
|
|
zh-CN: 定制回填内容
|
|
en-US: Custom selection render
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
使用 `optionLabelProp` 指定回填到选择框的 `Option` 属性。
|
|
|
|
## en-US
|
|
|
|
Spacified the prop name of Option which will be rendered in select box.
|
|
|
|
```jsx
|
|
import { Select } from 'antd';
|
|
|
|
const { Option } = Select;
|
|
|
|
function handleChange(value) {
|
|
console.log(`selected ${value}`);
|
|
}
|
|
|
|
ReactDOM.render(
|
|
<Select
|
|
mode="multiple"
|
|
style={{ width: '100%' }}
|
|
placeholder="select one country"
|
|
defaultValue={['china']}
|
|
onChange={handleChange}
|
|
optionLabelProp="label"
|
|
>
|
|
<Option value="china" label="China">
|
|
<div className="demo-option-label-item">
|
|
<span role="img" aria-label="China">
|
|
🇨🇳
|
|
</span>
|
|
China (中国)
|
|
</div>
|
|
</Option>
|
|
<Option value="usa" label="USA">
|
|
<div className="demo-option-label-item">
|
|
<span role="img" aria-label="USA">
|
|
🇺🇸
|
|
</span>
|
|
USA (美国)
|
|
</div>
|
|
</Option>
|
|
<Option value="japan" label="Japan">
|
|
<div className="demo-option-label-item">
|
|
<span role="img" aria-label="Japan">
|
|
🇯🇵
|
|
</span>
|
|
Japan (日本)
|
|
</div>
|
|
</Option>
|
|
<Option value="korea" label="Korea">
|
|
<div className="demo-option-label-item">
|
|
<span role="img" aria-label="Korea">
|
|
🇰🇷
|
|
</span>
|
|
Korea (韩国)
|
|
</div>
|
|
</Option>
|
|
</Select>,
|
|
mountNode,
|
|
);
|
|
```
|
|
|
|
```css
|
|
.demo-option-label-item > span {
|
|
margin-right: 6px;
|
|
}
|
|
```
|