Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/dialog/src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
name="dialog-fade"
@after-enter="afterEnter"
@after-leave="afterLeave">
<div class="el-dialog__wrapper" v-show="visible" @click.self="handleWrapperClick">
<div class="el-dialog__wrapper" v-show="visible" @click.self="handleWrapperClick" @mouseup="handleMouseup">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click.self 已经限制了点击事件是从当前元素触发,为什么还会关闭呢?再找找问题所在。https://cn.vuejs.org/v2/guide/events.html#%E4%BA%8B%E4%BB%B6%E4%BF%AE%E9%A5%B0%E7%AC%A6

Copy link
Contributor Author

@luckyCao luckyCao Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

场景是:点击dialog 内部,鼠标滑动到 dialog 外部时松开鼠标,dialog 会关闭。

self 修饰符是通过 target 和 currentTarget 的对比来 guard:

self: genGuard(`$event.target !== $event.currentTarget`)

click 事件的 event.targetdiv.el-dialog__wrapper,和 currentTarget 相等,所以用 self 修饰符没有效果

<div
role="dialog"
aria-modal="true"
:aria-label="title || 'dialog'"
class="el-dialog"
:class="[{ 'is-fullscreen': fullscreen, 'el-dialog--center': center }, customClass]"
ref="dialog"
:style="style">
:style="style"
@mousedown="handleMousedown">
<div class="el-dialog__header">
<slot name="title">
<span class="el-dialog__title">{{ title }}</span>
Expand Down Expand Up @@ -39,6 +40,8 @@
import Migrating from 'element-ui/src/mixins/migrating';
import emitter from 'element-ui/src/mixins/emitter';
let dialogMouseDown = false;
export default {
name: 'ElDialog',
Expand Down Expand Up @@ -152,9 +155,19 @@
};
},
handleWrapperClick() {
if (!this.closeOnClickModal) return;
if (!this.closeOnClickModal || dialogMouseDown) return;
this.handleClose();
},
handleMousedown() {
dialogMouseDown = true;
},
handleMouseup() {
if (dialogMouseDown) {
this.$nextTick(_ => {
dialogMouseDown = false;
});
}
},
handleClose() {
if (typeof this.beforeClose === 'function') {
this.beforeClose(this.hide);
Expand Down