diff --git a/components/drawer/Drawer.vue b/components/drawer/Drawer.vue index d17cb699b..2ec8b0993 100644 --- a/components/drawer/Drawer.vue +++ b/components/drawer/Drawer.vue @@ -3,8 +3,30 @@ :class="classes" class="mdc-drawer" @MDCDrawer:closed="onClosed" + @MDCDrawer:opened="onOpened" > - +
+

+ {{ title }} +

+
+ {{ subtitle }} +
+ +
+ @@ -31,11 +53,20 @@ export default { open: { type: Boolean, default: false + }, + title: { + type: String, + default: '' + }, + subtitle: { + type: String, + default: '' } }, data () { return { - mdcDrawer: undefined + mdcDrawer: undefined, + hasHeaderClass: false } }, computed: { @@ -56,17 +87,39 @@ export default { }, watch: { modal () { - if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el) + if (!this.modal) { + this.mdcDrawer.destroy() + this.mdcDrawer = undefined + } else { + this.$nextTick(function () { + this.mdcDrawer = new MDCDrawer(this.$el) + }) + } }, dismissible () { - if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el) + if (!this.dismissible) { + this.mdcDrawer.destroy() + this.mdcDrawer = undefined + } else { + this.$nextTick(function () { + this.mdcDrawer = new MDCDrawer(this.$el) + }) + } }, open () { - this.mdcDrawer.open = this.open + if (this.mdcDrawer.open !== this.open) this.mdcDrawer.open = this.open + }, + 'mdcDrawer.open': function () { + this.model = this.mdcDrawer.open } }, mounted () { - if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) } + // the slots can only be accessible in nextTick + this.$nextTick(function () { + // judge whether the slots have the header class + this.hasHeaderClass = this.$slots.header[0].elm.classList.contains('mdc-drawer__header') + if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) } + }) }, provide: { mdcDrawer: this @@ -76,8 +129,11 @@ export default { }, methods: { onClosed () { - this.model = false + if (this.model) this.model = false this.$emit('closed') + }, + onOpened () { + this.$emit('opened') } } } diff --git a/components/drawer/DrawerContent.vue b/components/drawer/DrawerContent.vue index f6cfd5f5c..bc2eefde7 100644 --- a/components/drawer/DrawerContent.vue +++ b/components/drawer/DrawerContent.vue @@ -2,6 +2,7 @@
diff --git a/components/drawer/DrawerHeader.vue b/components/drawer/DrawerHeader.vue index c51e485c8..feca6dcf9 100644 --- a/components/drawer/DrawerHeader.vue +++ b/components/drawer/DrawerHeader.vue @@ -1,6 +1,6 @@