Skip to content
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

fix(dropdown-menu): 修复点击下拉框以外区域下拉框需要收起问题 #1369

Merged
merged 2 commits into from
May 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/dropdown-menu/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type TriggerSource = 'overlay' | 'menu' | 'content' | 'confirm';
export type TriggerSource = 'overlay' | 'menu' | 'content' | 'confirm' | 'outside';

export type DropdownMenuDo = () => void;

Expand Down
1 change: 1 addition & 0 deletions src/dropdown-menu/dropdown-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export default defineComponent({
const content = renderContent('default', 'content');

const footer = renderTNodeJSX('footer');

return (
wrapperVisible.value && (
<div id={popupId} class={classes.value} style={{ ...expandStyle.value }}>
Expand Down
9 changes: 8 additions & 1 deletion src/dropdown-menu/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, computed, ref, reactive, watch, provide } from 'vue';

import { onClickOutside } from '@vueuse/core';
import { CaretDownSmallIcon, CaretUpSmallIcon } from 'tdesign-icons-vue-next';
import camelCase from 'lodash/camelCase';

Expand Down Expand Up @@ -133,6 +133,13 @@ export default defineComponent({
const container = findRelativeContainer(bar) || document.body;
menuContext.recordMenuExpanded(container, control, DropdownMenuExpandState.collapsed);
};

// dropdown-menu外面点击触发dropdown下拉框收起
onClickOutside(refBar, () => {
collapseMenu();
props.onMenuClosed?.({ trigger: 'outside' });
});

const control: DropdownMenuControl = {
expandMenu,
collapseMenu,
Expand Down
Loading