Skip to content

fix(dropdown): fix close popup doesn't emit 'visibleChange' event #6416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/dropdown/demo/event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ An event will be triggered when you click menu items, in which you can make diff
</docs>

<template>
<a-dropdown>
<a-dropdown @visible-change="handleVisibleChange">
<a class="ant-dropdown-link" @click.prevent>
Hover me, Click menu item
<DownOutlined />
Expand All @@ -44,8 +44,12 @@ export default defineComponent({
const onClick: MenuProps['onClick'] = ({ key }) => {
console.log(`Click on item ${key}`);
};
const handleVisibleChange = (value: boolean) => {
console.log('visible', value);
};
return {
onClick,
handleVisibleChange,
};
},
});
Expand Down
5 changes: 3 additions & 2 deletions components/vc-dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ export default defineComponent({
});

const onClick = (e: MouseEvent) => {
if (triggerVisible.value !== props.visible) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个还是 revert 吧,这样也不靠谱

Copy link
Member Author

@CCherry07 CCherry07 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来那个,会有bug,我感觉可能是trigger 组件的问题,这个问题的引起可能是那个 sPopupVisible 这个状态,被两个地方进行修改,一个是监听了props.popupVisible ,另外一个是 setPopupVisible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,先回滚掉,原来只是不触发 visibleChange,影响较小,可以再看看根本问题
话说 antd react 应该也有问题吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档明确说了click不触发onVisibleChange,虽然这行为也挺让人难理解的

emit('visibleChange', props.visible === undefined ? !triggerVisible.value : props.visible);
}
if (props.visible === undefined) {
triggerVisible.value = false;
}

emit('visibleChange', false);
emit('overlayClick', e);
};

Expand Down