Skip to content

Commit

Permalink
fix(dropdown-menu): 修复点击下拉框以外区域下拉框需要收起问题 (#1369)
Browse files Browse the repository at this point in the history
* fix(dropdown-menu): 修复点击下拉框以外区域下拉框需要收起问题

* fix(dropdown-menu): 修复点击下拉框以外区域下拉框需要收起问题
  • Loading branch information
aaronmhl authored May 10, 2024
1 parent f2a25bf commit c094ab4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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

0 comments on commit c094ab4

Please sign in to comment.