mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 18:36:51 +08:00
[bugfix] Toast: mask render uncorrectly when forbidClick (#1154)
This commit is contained in:
parent
aa89f1a26c
commit
6d1c0ef2a5
@ -33,10 +33,6 @@ function createInstance() {
|
|||||||
// transform toast options to popup props
|
// transform toast options to popup props
|
||||||
function transformer(options) {
|
function transformer(options) {
|
||||||
options.overlay = options.mask;
|
options.overlay = options.mask;
|
||||||
if (options.forbidClick && !options.overlay) {
|
|
||||||
options.overlay = true;
|
|
||||||
options.overlayStyle = { background: 'transparent' };
|
|
||||||
}
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,20 @@ import { TransitionStub } from '@vue/test-utils';
|
|||||||
|
|
||||||
Vue.component('transition', TransitionStub);
|
Vue.component('transition', TransitionStub);
|
||||||
|
|
||||||
test('create a forbidClick toast', () => {
|
test('create a forbidClick toast', done => {
|
||||||
const toast = Toast({
|
const toast = Toast({
|
||||||
forbidClick: true
|
forbidClick: true
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(toast.$el.outerHTML).toMatchSnapshot();
|
expect(toast.$el.outerHTML).toMatchSnapshot();
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(document.body.classList.contains('van-toast--unclickable')).toBeTruthy();
|
||||||
|
toast.forbidClick = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(document.body.classList.contains('van-toast--unclickable')).toBeFalsy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toast disappeared after duration', (done) => {
|
it('toast disappeared after duration', (done) => {
|
||||||
@ -20,7 +28,7 @@ it('toast disappeared after duration', (done) => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(toast.$el.style.display).toEqual('none');
|
expect(toast.$el.style.display).toEqual('none');
|
||||||
done();
|
done();
|
||||||
}, 500);
|
}, 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clear toast', () => {
|
test('clear toast', () => {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<transition name="van-fade">
|
<transition name="van-fade">
|
||||||
<div v-show="value" :class="b([displayStyle, position])">
|
<div v-show="value" :class="b([style, position])">
|
||||||
<!-- text only -->
|
<!-- text only -->
|
||||||
<div v-if="displayStyle === 'text'">{{ message }}</div>
|
<div v-if="style === 'text'">{{ message }}</div>
|
||||||
<div v-if="displayStyle === 'html'" v-html="message" />
|
<div v-if="style === 'html'" v-html="message" />
|
||||||
|
|
||||||
<!-- with icon -->
|
<!-- with icon -->
|
||||||
<template v-if="displayStyle === 'default'">
|
<template v-if="style === 'default'">
|
||||||
<loading v-if="type === 'loading'" color="white" :type="loadingType" />
|
<loading v-if="type === 'loading'" color="white" :type="loadingType" />
|
||||||
<icon v-else :class="b('icon')" :name="type" />
|
<icon v-else :class="b('icon')" :name="type" />
|
||||||
<div v-if="isDef(message)" :class="b('text')">{{ message }}</div>
|
<div v-if="isDef(message)" :class="b('text')">{{ message }}</div>
|
||||||
@ -27,6 +27,7 @@ export default create({
|
|||||||
mixins: [Popup],
|
mixins: [Popup],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
forbidClick: Boolean,
|
||||||
message: [String, Number],
|
message: [String, Number],
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -46,10 +47,41 @@ export default create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
clickable: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
displayStyle() {
|
style() {
|
||||||
return STYLE_LIST.indexOf(this.type) !== -1 ? 'default' : this.type;
|
return STYLE_LIST.indexOf(this.type) !== -1 ? 'default' : this.type;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.toggleClickale();
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value() {
|
||||||
|
this.toggleClickale();
|
||||||
|
},
|
||||||
|
|
||||||
|
forbidClick() {
|
||||||
|
this.toggleClickale();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
toggleClickale() {
|
||||||
|
const clickable = this.value && this.forbidClick;
|
||||||
|
if (this.clickable !== clickable) {
|
||||||
|
this.clickable = clickable;
|
||||||
|
const action = clickable ? 'add' : 'remove';
|
||||||
|
document.body.classList[action]('van-toast--unclickable');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
transform: translate3d(-50%, -50%, 0);
|
transform: translate3d(-50%, -50%, 0);
|
||||||
background-color: rgba(0, 0, 0, .7);
|
background-color: rgba(0, 0, 0, .7);
|
||||||
|
|
||||||
|
&--unclickable {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
&--text {
|
&--text {
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
min-width: 220px;
|
min-width: 220px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user