[bugfix] Dialog: overlay incorrect locate when use getContainer (#3041)

This commit is contained in:
neverland 2019-03-22 16:16:35 +08:00 committed by GitHub
parent c1adaebaa6
commit 784b279738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 15 deletions

View File

@ -2,7 +2,6 @@ import { OverlayConfig } from './overlay';
export type StackItem = { export type StackItem = {
vm: any; vm: any;
target: HTMLElement;
config: OverlayConfig; config: OverlayConfig;
}; };

View File

@ -1,7 +1,7 @@
import { context } from './context'; import { context } from './context';
import { TouchMixin } from '../touch'; import { TouchMixin } from '../touch';
import { on, off } from '../../utils/event'; import { on, off } from '../../utils/event';
import { openOverlay, closeOverlay } from './overlay'; import { openOverlay, closeOverlay, updateOverlay } from './overlay';
import { getScrollEventTarget } from '../../utils/scroll'; import { getScrollEventTarget } from '../../utils/scroll';
export const PopupMixin = { export const PopupMixin = {
@ -154,6 +154,10 @@ export const PopupMixin = {
if (container && container !== this.$el.parentNode) { if (container && container !== this.$el.parentNode) {
container.appendChild(this.$el); container.appendChild(this.$el);
} }
if (this.overlay) {
updateOverlay();
}
}, },
onTouchMove(e) { onTouchMove(e) {

View File

@ -31,7 +31,7 @@ function onClickOverlay(): void {
} }
} }
function updateOverlay(): void { export function updateOverlay(): void {
if (!overlay) { if (!overlay) {
overlay = mount(Overlay, { overlay = mount(Overlay, {
on: { on: {
@ -40,26 +40,26 @@ function updateOverlay(): void {
}); });
} }
if (overlay.$el.parentNode) {
overlay.visible = false;
}
if (context.top) { if (context.top) {
const { target, config } = context.top; const { vm, config } = context.top;
const el = vm.$el;
const target = el && el.parentNode ? el.parentNode : document.body;
if (target) {
target.appendChild(overlay.$el);
}
target.appendChild(overlay.$el);
Object.assign(overlay, defaultConfig, config, { Object.assign(overlay, defaultConfig, config, {
visible: true visible: true
}); });
} else {
overlay.visible = false;
} }
} }
export function openOverlay(vm: any, config: OverlayConfig): void { export function openOverlay(vm: any, config: OverlayConfig): void {
/* istanbul ignore next */
if (!context.stack.some(item => item.vm === vm)) { if (!context.stack.some(item => item.vm === vm)) {
const el = vm.$el; context.stack.push({ vm, config });
const target = el && el.parentNode ? el.parentNode : document.body;
context.stack.push({ vm, config, target });
updateOverlay(); updateOverlay();
} }
} }

View File

@ -60,9 +60,11 @@ function Toast(options = {}) {
clearTimeout(toast.timer); clearTimeout(toast.timer);
queue = queue.filter(item => item !== toast); queue = queue.filter(item => item !== toast);
if (document.body.contains(toast.$el)) { const parent = toast.$el.parentNode;
document.body.removeChild(toast.$el); if (parent) {
parent.removeChild(toast.$el);
} }
toast.$destroy(); toast.$destroy();
} }
} }