fix: modal cannot open in dropdown, close #5139

pull/5147/head
tangjinzhou 2022-01-10 10:23:17 +08:00
parent 3d3dcd5c44
commit f6d1b848e4
2 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import type { IDialogChildProps } from './IDialogPropTypes';
import getDialogPropTypes from './IDialogPropTypes'; import getDialogPropTypes from './IDialogPropTypes';
import Portal from '../_util/PortalWrapper'; import Portal from '../_util/PortalWrapper';
import { defineComponent, ref, watch } from 'vue'; import { defineComponent, ref, watch } from 'vue';
import { useProvidePortal } from '../vc-trigger/context';
const IDialogPropTypes = getDialogPropTypes(); const IDialogPropTypes = getDialogPropTypes();
const DialogWrap = defineComponent({ const DialogWrap = defineComponent({
name: 'DialogWrap', name: 'DialogWrap',
@ -13,6 +14,7 @@ const DialogWrap = defineComponent({
}, },
setup(props, { attrs, slots }) { setup(props, { attrs, slots }) {
const animatedVisible = ref(props.visible); const animatedVisible = ref(props.visible);
useProvidePortal({}, { inTriggerContext: false });
watch( watch(
() => props.visible, () => props.visible,
() => { () => {

View File

@ -27,11 +27,11 @@ export interface PortalContextProps {
inTriggerContext: boolean; // 仅处理 trigger 上下文的 portal inTriggerContext: boolean; // 仅处理 trigger 上下文的 portal
} }
const PortalContextKey: InjectionKey<PortalContextProps> = Symbol('PortalContextKey'); const PortalContextKey: InjectionKey<PortalContextProps> = Symbol('PortalContextKey');
export const useProvidePortal = (instance: any) => { export const useProvidePortal = (instance: any, config = { inTriggerContext: true }) => {
provide(PortalContextKey, { provide(PortalContextKey, {
inTriggerContext: true, inTriggerContext: config.inTriggerContext,
shouldRender: computed(() => { shouldRender: computed(() => {
const { sPopupVisible, popupRef, forceRender, autoDestroy } = instance; const { sPopupVisible, popupRef, forceRender, autoDestroy } = instance || {};
// if (popPortal) return true; // if (popPortal) return true;
let shouldRender = false; let shouldRender = false;
if (sPopupVisible || popupRef || forceRender) { if (sPopupVisible || popupRef || forceRender) {
@ -46,6 +46,7 @@ export const useProvidePortal = (instance: any) => {
}; };
export const useInjectPortal = () => { export const useInjectPortal = () => {
useProvidePortal({}, { inTriggerContext: false });
const portalContext = inject(PortalContextKey, { const portalContext = inject(PortalContextKey, {
shouldRender: computed(() => false), shouldRender: computed(() => false),
inTriggerContext: false, inTriggerContext: false,