mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 17:59:57 +08:00
7fd093bd0a
* docs: add general components TS demo * docs: add layout components TS demo * docs: add navigation components TS demo * docs: add data entry components TS demo * chore(deps): add types for qs * docs: add data display TS demo * docs: add feedback components TS demo * docs: add other components TS demo * chore(deps): add types * docs: unified demo code style * docs: fix lint error * docs: add demo TS type * docs: fix demo TS type * test: update snapshot * docs: fix TS demo * feat: update Rate character type * docs: fix lint error * feat: update Rate character type * feat: update Rate character type
1.6 KiB
1.6 KiB
order | title | ||||
---|---|---|---|---|---|
4 |
|
zh-CN
使用 optionLabelProp
指定回填到选择框的 Option
属性。
en-US
Specify the prop name of Option which will be rendered in select box.
import React from 'react';
import { Select } from 'antd';
const { Option } = Select;
const handleChange = (value: string[]) => {
console.log(`selected ${value}`);
};
const App: React.FC = () => (
<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>
);
export default App;
.demo-option-label-item > span {
margin-right: 6px;
}