mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
1.1 KiB
1.1 KiB
order | title | ||||
---|---|---|---|---|---|
4 |
|
zh-CN
点击菜单项后会触发事件,用户可以通过相应的菜单项 key 进行不同的操作。
en-US
An event will be triggered when you click menu items, in which you can make different operations according to item's key.
import { DownOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Dropdown, Menu, message, Space } from 'antd';
import React from 'react';
const onClick: MenuProps['onClick'] = ({ key }) => {
message.info(`Click on item ${key}`);
};
const menu = (
<Menu
onClick={onClick}
items={[
{
label: '1st menu item',
key: '1',
},
{
label: '2nd menu item',
key: '2',
},
{
label: '3rd menu item',
key: '3',
},
]}
/>
);
const App: React.FC = () => (
<Dropdown overlay={menu}>
<a onClick={e => e.preventDefault()}>
<Space>
Hover me, Click menu item
<DownOutlined />
</Space>
</a>
</Dropdown>
);
export default App;