mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-06 02:15:35 +08:00
64b905e9bd
* update icons deps * update all icon ref * fix lint * update snapshot
77 lines
1.6 KiB
Markdown
77 lines
1.6 KiB
Markdown
---
|
|
order: 21
|
|
title:
|
|
zh-CN: 扩展菜单
|
|
en-US: Custom dropdown
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
使用 `dropdownRender` 对下拉菜单进行自由扩展。
|
|
|
|
## en-US
|
|
|
|
Customize the dropdown menu via `dropdownRender`.
|
|
|
|
```jsx
|
|
import { Select, Divider, Input } from 'antd';
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
|
|
const { Option } = Select;
|
|
|
|
let index = 0;
|
|
|
|
class App extends React.Component {
|
|
state = {
|
|
items: ['jack', 'lucy'],
|
|
name: '',
|
|
};
|
|
|
|
onNameChange = event => {
|
|
this.setState({
|
|
name: event.target.value,
|
|
});
|
|
};
|
|
|
|
addItem = () => {
|
|
console.log('addItem');
|
|
const { items, name } = this.state;
|
|
this.setState({
|
|
items: [...items, name || `New item ${index++}`],
|
|
name: '',
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const { items, name } = this.state;
|
|
return (
|
|
<Select
|
|
style={{ width: 240 }}
|
|
placeholder="custom dropdown render"
|
|
dropdownRender={menu => (
|
|
<div>
|
|
{menu}
|
|
<Divider style={{ margin: '4px 0' }} />
|
|
<div style={{ display: 'flex', flexWrap: 'nowrap', padding: 8 }}>
|
|
<Input style={{ flex: 'auto' }} value={name} onChange={this.onNameChange} />
|
|
<a
|
|
style={{ flex: 'none', padding: '8px', display: 'block', cursor: 'pointer' }}
|
|
onClick={this.addItem}
|
|
>
|
|
<PlusOutlined /> Add item
|
|
</a>
|
|
</div>
|
|
</div>
|
|
)}
|
|
>
|
|
{items.map(item => (
|
|
<Option key={item}>{item}</Option>
|
|
))}
|
|
</Select>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
```
|