[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 = {
vm: any;
target: HTMLElement;
config: OverlayConfig;
};

View File

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

View File

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

View File

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