ant-design/components/select/demo/option-render.tsx
叶枫 ff231ab557
demo: remove optionLabelProp (#48186)
* feat: remove optioLabelProp

* feat: doc

* feat: doc

* feat: option-render

* feat: option-render

* feat: snap
2024-04-01 11:09:23 +08:00

56 lines
1.0 KiB
TypeScript

import React from 'react';
import type { SelectProps } from 'antd';
import { Select, Space } from 'antd';
const handleChange = (value: string[]) => {
console.log(`selected ${value}`);
};
const options: SelectProps['options'] = [
{
label: 'China',
value: 'china',
emoji: '🇨🇳',
desc: 'China (中国)',
},
{
label: 'USA',
value: 'usa',
emoji: '🇺🇸',
desc: 'USA (美国)',
},
{
label: 'Japan',
value: 'japan',
emoji: '🇯🇵',
desc: 'Japan (日本)',
},
{
label: 'Korea',
value: 'korea',
emoji: '🇰🇷',
desc: 'Korea (韩国)',
},
];
const App: React.FC = () => (
<Select
mode="multiple"
style={{ width: '100%' }}
placeholder="select one country"
defaultValue={['china']}
onChange={handleChange}
options={options}
optionRender={(option) => (
<Space>
<span role="img" aria-label={option.data.label}>
{option.data.emoji}
</span>
{option.data.desc}
</Space>
)}
/>
);
export default App;