2018-11-27 12:01:30 +08:00
|
|
|
---
|
|
|
|
order: 21
|
|
|
|
title:
|
|
|
|
zh-CN: 扩展菜单
|
|
|
|
en-US: Custom dropdown
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `dropdownRender` 对下拉菜单进行自由扩展。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Customize the dropdown menu via `dropdownRender`.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2019-09-26 22:28:08 +08:00
|
|
|
import { Select, Divider } from 'antd';
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Plus } from '@ant-design/icons';
|
2018-11-27 12:01:30 +08:00
|
|
|
|
2019-05-27 21:32:45 +08:00
|
|
|
const { Option } = Select;
|
2018-11-27 12:01:30 +08:00
|
|
|
|
2019-09-24 22:37:34 +08:00
|
|
|
let index = 0;
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
|
|
|
items: ['jack', 'lucy'],
|
|
|
|
};
|
|
|
|
|
|
|
|
addItem = () => {
|
|
|
|
console.log('addItem');
|
|
|
|
const { items } = this.state;
|
|
|
|
this.setState({
|
|
|
|
items: [...items, `New item ${index++}`],
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { items } = this.state;
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
style={{ width: 240 }}
|
|
|
|
placeholder="custom dropdown render"
|
|
|
|
dropdownRender={menu => (
|
|
|
|
<div>
|
|
|
|
{menu}
|
|
|
|
<Divider style={{ margin: '4px 0' }} />
|
2019-09-26 22:28:08 +08:00
|
|
|
<a
|
|
|
|
style={{ padding: '8px', display: 'block', cursor: 'pointer' }}
|
2019-09-24 22:37:34 +08:00
|
|
|
onClick={this.addItem}
|
|
|
|
>
|
2019-09-26 22:28:08 +08:00
|
|
|
<Plus /> Add item
|
|
|
|
</a>
|
2019-09-24 22:37:34 +08:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{items.map(item => (
|
|
|
|
<Option key={item}>{item}</Option>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|