[improvement] DropdownMenu: optimize transition

This commit is contained in:
陈嘉涵
2019-05-23 19:56:07 +08:00
parent d7e5ee40b5
commit 9bce0aa31b
4 changed files with 38 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { use, isDef } from '../utils';
import { use } from '../utils';
import Cell from '../cell';
import Icon from '../icon';
import Popup from '../popup';
@@ -19,7 +19,9 @@ export default sfc({
data() {
return {
show: false
transition: true,
showPopup: false,
showWrapper: false
};
},
@@ -36,7 +38,19 @@ export default sfc({
methods: {
toggle(show) {
this.show = isDef(show) ? show : !this.show;
this.showPopup = !this.showPopup;
if (this.showPopup) {
this.showWrapper = true;
}
},
hide(skipTransition) {
this.showPopup = false;
if (skipTransition) {
this.transition = false;
}
}
},
@@ -52,7 +66,7 @@ export default sfc({
title={option.text}
titleStyle={{ color: active ? activeColor : '' }}
onClick={() => {
this.show = false;
this.showPopup = false;
if (option.value !== this.value) {
this.$emit('input', option.value);
@@ -68,11 +82,11 @@ export default sfc({
const emit = eventName => () => this.$emit(eventName);
return (
<div vShow={this.show} style={{ top: `${top}px`, zIndex }} class={bem()}>
<div vShow={this.showWrapper} style={{ top: `${top}px`, zIndex }} class={bem()}>
<Popup
vModel={this.show}
vModel={this.showPopup}
position="top"
duration={0.2}
duration={this.transition ? 0.2 : 0}
class={bem('content')}
overlay={overlay}
closeOnClickOverlay={closeOnClickOverlay}
@@ -80,6 +94,11 @@ export default sfc({
onOpen={emit('open')}
onOpened={emit('opened')}
onClose={emit('close')}
onClosed={() => {
this.transition = true;
this.showWrapper = false;
this.$emit('closed');
}}
>
{Options}
{this.slots('default')}