mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 23:59:12 +08:00
58df74c38e
* docs(badge): replace class component with hooks * docs(button): replace class component with hooks * docs(calendar): replace class component with hooks * docs(card): replace class component with hooks * docs(button): replace class component with hooks * chore(deps): remove webpack devDependencies * docs(cascader): replace class component with hooks * docs(checkbox): replace class component with hooks * docs(collapse): replace class component with hooks * docs(comment): replace class component with hooks * docs(descriptions): replace class component with hooks * docs(config-provider): replace class component with hooks * docs(date-picker): replace class component with hooks * docs(drawer): replace class component with hooks * docs(dropdown): replace class component with hooks * docs(dropdown): replace class component with hooks * docs(empty): replace class component with hooks * docs(grid): replace class component with hooks * docs(input): replace class component with hooks * docs(input-number): replace class component with hooks * docs(demo): fix lint error
1.2 KiB
1.2 KiB
order | title | ||||
---|---|---|---|---|---|
7 |
|
zh-CN
默认是点击关闭菜单,可以关闭此功能。
en-US
The default is to close the menu when you click on menu items, this feature can be turned off.
import { Menu, Dropdown, Space } from 'antd';
import { DownOutlined } from '@ant-design/icons';
export default () => {
const [visible, setVisible] = React.useState(false);
const handleMenuClick = e => {
if (e.key === '3') {
setVisible(false);
}
};
const handleVisibleChange = flag => {
setVisible(flag);
};
const menu = (
<Menu
onClick={handleMenuClick}
items={[
{
label: 'Clicking me will not close the menu.',
key: '1',
},
{
label: 'Clicking me will not close the menu also.',
key: '2',
},
{
label: 'Clicking me will close the menu.',
key: '3',
},
]}
/>
);
return (
<Dropdown overlay={menu} onVisibleChange={handleVisibleChange} visible={visible}>
<a onClick={e => e.preventDefault()}>
<Space>
Hover me
<DownOutlined />
</Space>
</a>
</Dropdown>
);
};