Skip to content

Commit

Permalink
fix: modal cannot open in dropdown, close #5139
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jan 10, 2022
1 parent 3d3dcd5 commit f6d1b84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions components/vc-dialog/DialogWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IDialogChildProps } from './IDialogPropTypes';
import getDialogPropTypes from './IDialogPropTypes';
import Portal from '../_util/PortalWrapper';
import { defineComponent, ref, watch } from 'vue';
import { useProvidePortal } from '../vc-trigger/context';
const IDialogPropTypes = getDialogPropTypes();
const DialogWrap = defineComponent({
name: 'DialogWrap',
Expand All @@ -13,6 +14,7 @@ const DialogWrap = defineComponent({
},
setup(props, { attrs, slots }) {
const animatedVisible = ref(props.visible);
useProvidePortal({}, { inTriggerContext: false });
watch(
() => props.visible,
() => {
Expand Down
7 changes: 4 additions & 3 deletions components/vc-trigger/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface PortalContextProps {
inTriggerContext: boolean; // 仅处理 trigger 上下文的 portal
}
const PortalContextKey: InjectionKey<PortalContextProps> = Symbol('PortalContextKey');
export const useProvidePortal = (instance: any) => {
export const useProvidePortal = (instance: any, config = { inTriggerContext: true }) => {
provide(PortalContextKey, {
inTriggerContext: true,
inTriggerContext: config.inTriggerContext,
shouldRender: computed(() => {
const { sPopupVisible, popupRef, forceRender, autoDestroy } = instance;
const { sPopupVisible, popupRef, forceRender, autoDestroy } = instance || {};
// if (popPortal) return true;
let shouldRender = false;
if (sPopupVisible || popupRef || forceRender) {
Expand All @@ -46,6 +46,7 @@ export const useProvidePortal = (instance: any) => {
};

export const useInjectPortal = () => {
useProvidePortal({}, { inTriggerContext: false });
const portalContext = inject(PortalContextKey, {
shouldRender: computed(() => false),
inTriggerContext: false,
Expand Down

0 comments on commit f6d1b84

Please sign in to comment.