MessageBox: fix text blur due to translating half pixel

This commit is contained in:
Leopoldthecoder 2016-11-05 20:40:00 +08:00 committed by cinwell.li
parent c2a937ce02
commit d5eb9ac3b5
3 changed files with 42 additions and 21 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="el-message-box__wrapper"> <transition name="msgbox-fade">
<transition name="msgbox-fade"> <div class="el-message-box__wrapper" v-show="value" @click.self="handleWrapperClick">
<div class="el-message-box" v-show="value"> <div class="el-message-box">
<div class="el-message-box__header" v-if="title !== ''"> <div class="el-message-box__header" v-if="title !== ''">
<div class="el-message-box__title">{{ title }}</div> <div class="el-message-box__title">{{ title }}</div>
<i class="el-message-box__close el-icon-close" @click="handleAction('cancel')" v-if="showClose"></i> <i class="el-message-box__close el-icon-close" @click="handleAction('cancel')" v-if="showClose"></i>
@ -19,8 +19,8 @@
<el-button ref="confirm" :class="[ confirmButtonClasses ]" v-show="showConfirmButton" @click.native="handleAction('confirm')">{{ confirmButtonText }}</el-button> <el-button ref="confirm" :class="[ confirmButtonClasses ]" v-show="showConfirmButton" @click.native="handleAction('confirm')">{{ confirmButtonText }}</el-button>
</div> </div>
</div> </div>
</transition> </div>
</div> </transition>
</template> </template>
<script type="text/babel"> <script type="text/babel">
@ -101,6 +101,12 @@
} }
}, },
handleWrapperClick() {
if (this.closeOnClickModal) {
this.close();
}
},
handleAction(action) { handleAction(action) {
if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) { if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
return; return;

View File

@ -7,10 +7,9 @@
@component-namespace el { @component-namespace el {
@b message-box { @b message-box {
position: fixed; text-align: left;
top: 50%; display: inline-block;
left: 50%; vertical-align: middle;
transform: translate3d(-50%, -50%, 0);
background-color: #fff; background-color: #fff;
width: var(--msgbox-width); width: var(--msgbox-width);
border-radius: var(--msgbox-border-radius); border-radius: var(--msgbox-border-radius);
@ -18,8 +17,24 @@
-webkit-user-select: none; -webkit-user-select: none;
overflow: hidden; overflow: hidden;
backface-visibility: hidden; backface-visibility: hidden;
@e wrapper {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
&::after {
content: "";
display: inline-block;
height: 100%;
width: 0;
vertical-align: middle;
}
}
@e header { @e header {
position: relative;
padding: 20px 20px 0; padding: 20px 20px 0;
} }
@ -128,22 +143,22 @@
@keyframes msgbox-fade-in { @keyframes msgbox-fade-in {
0% { 0% {
transform: translate3d(-50%, calc(-50% - 20px), 0); transform: translate3d(0, -20px, 0);
opacity: 0; opacity: 0;
} }
100% { 100% {
transform: translate3d(-50%, -50%, 0); transform: translate3d(0, 0, 0);
opacity: 1; opacity: 1;
} }
} }
@keyframes msgbox-fade-out { @keyframes msgbox-fade-out {
0% { 0% {
transform: translate3d(-50%, -50%, 0); transform: translate3d(0, 0, 0);
opacity: 1; opacity: 1;
} }
100% { 100% {
transform: translate3d(-50%, calc(-50% - 20px), 0); transform: translate3d(0, -20px, 0);
opacity: 0; opacity: 0;
} }
} }

View File

@ -32,12 +32,12 @@ describe('MessageBox', () => {
}); });
setTimeout(() => { setTimeout(() => {
const msgbox = document.querySelector('.el-message-box__wrapper'); const msgbox = document.querySelector('.el-message-box__wrapper');
expect(msgbox.__vue__.value).to.true; expect(msgbox.__vue__.$parent.value).to.true;
expect(msgbox.querySelector('.el-message-box__title').textContent).to.equal('消息'); expect(msgbox.querySelector('.el-message-box__title').textContent).to.equal('消息');
expect(msgbox.querySelector('.el-message-box__message') expect(msgbox.querySelector('.el-message-box__message')
.querySelector('p').textContent).to.equal('这是一段内容'); .querySelector('p').textContent).to.equal('这是一段内容');
MessageBox.close(); MessageBox.close();
expect(msgbox.__vue__.value).to.false; expect(msgbox.__vue__.$parent.value).to.false;
done(); done();
}, 300); }, 300);
}); });
@ -58,9 +58,9 @@ describe('MessageBox', () => {
setTimeout(() => { setTimeout(() => {
document.querySelector('.v-modal').click(); document.querySelector('.v-modal').click();
expect(document.querySelector('.el-message-box__wrapper') expect(document.querySelector('.el-message-box__wrapper')
.__vue__.value).to.true; .__vue__.$parent.value).to.true;
expect(document.querySelector('.el-message-box__wrapper') expect(document.querySelector('.el-message-box__wrapper')
.__vue__.type).to.equal('warning'); .__vue__.$parent.type).to.equal('warning');
done(); done();
}, 300); }, 300);
}); });
@ -74,7 +74,7 @@ describe('MessageBox', () => {
document.querySelector('.el-message-box__wrapper') document.querySelector('.el-message-box__wrapper')
.querySelector('.el-button--primary').click(); .querySelector('.el-button--primary').click();
expect(document.querySelector('.el-message-box__wrapper') expect(document.querySelector('.el-message-box__wrapper')
.__vue__.value).to.false; .__vue__.$parent.value).to.false;
done(); done();
}, 200); }, 200);
}); });
@ -87,7 +87,7 @@ describe('MessageBox', () => {
}); });
setTimeout(() => { setTimeout(() => {
expect(document.querySelector('.el-message-box__input')).to.exist; expect(document.querySelector('.el-message-box__input')).to.exist;
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__; const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
messageBox.inputValue = 'no'; messageBox.inputValue = 'no';
setTimeout(() => { setTimeout(() => {
expect(document.querySelector('.el-message-box__errormsg') expect(document.querySelector('.el-message-box__errormsg')
@ -108,7 +108,7 @@ describe('MessageBox', () => {
inputValidator: validator inputValidator: validator
}); });
setTimeout(() => { setTimeout(() => {
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__; const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
messageBox.inputValue = 'no'; messageBox.inputValue = 'no';
setTimeout(() => { setTimeout(() => {
expect(document.querySelector('.el-message-box__errormsg') expect(document.querySelector('.el-message-box__errormsg')
@ -130,7 +130,7 @@ describe('MessageBox', () => {
inputValidator: validator inputValidator: validator
}); });
setTimeout(() => { setTimeout(() => {
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__; const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
messageBox.inputValue = 'no'; messageBox.inputValue = 'no';
setTimeout(() => { setTimeout(() => {
expect(document.querySelector('.el-message-box__errormsg') expect(document.querySelector('.el-message-box__errormsg')