Skip to content

Commit 10c64e3

Browse files
authored
fix(v-navigation-drawer): update drawer states reactivity with permanent (#2495)
* fix(v-navigation-drawer): update drawer states reactivity with permanent fixes #2493 * Create failing test cases * simplfied logic, fixed tests, added one * remove overlay when being resized from mobile to desktop and active * run tryOverlay when temporary toggles * test: use expect().toBeTruthy() * Remove booting from drawer - Prevents the initial animation on non-ssr pages - Uses a ref hack to set the correct styles on content elements - see vuejs/vue#7063
1 parent b7b55b4 commit 10c64e3

File tree

7 files changed

+124
-334
lines changed

7 files changed

+124
-334
lines changed

src/components/VApp/mixins/app-breakpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const breakpoint = {
108108
}
109109
},
110110

111-
mounted () {
111+
created () {
112112
this.$vuetify.breakpoint = this.breakpoint
113113
},
114114

src/components/VBottomNav/VBottomNav.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export default {
6060

6161
render (h) {
6262
return h('div', {
63-
class: this.addBackgroundColorClassChecks(this.classes)
63+
class: this.addBackgroundColorClassChecks(this.classes),
64+
ref: 'content'
6465
}, this.$slots.default)
6566
}
6667
}

src/components/VFooter/VFooter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export default {
5959
style: {
6060
paddingLeft: `${this.paddingLeft}px`,
6161
paddingRight: `${this.paddingRight}px`
62-
}
62+
},
63+
ref: 'content'
6364
}
6465

6566
return h('footer', data, this.$slots.default)

src/components/VGrid/VContent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export default {
3535
render (h) {
3636
const data = {
3737
staticClass: 'content',
38-
style: this.styles
38+
style: this.styles,
39+
ref: 'content'
3940
}
4041

4142
return h('div', {

src/components/VNavigationDrawer/VNavigationDrawer.js

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default {
2222
data () {
2323
return {
2424
isActive: false,
25-
isBooted: false,
2625
isMobile: null,
2726
touchArea: {
2827
left: 0,
@@ -74,13 +73,12 @@ export default {
7473
'navigation-drawer': true,
7574
'navigation-drawer--absolute': this.absolute,
7675
'navigation-drawer--clipped': this.clipped,
77-
'navigation-drawer--close': !this.isBooted || !this.isActive,
76+
'navigation-drawer--close': !this.isActive,
7877
'navigation-drawer--fixed': this.fixed,
7978
'navigation-drawer--floating': this.floating,
80-
'navigation-drawer--is-booted': this.isBooted,
8179
'navigation-drawer--is-mobile': this.isMobile,
8280
'navigation-drawer--mini-variant': this.miniVariant,
83-
'navigation-drawer--open': this.isActive && this.isBooted,
81+
'navigation-drawer--open': this.isActive,
8482
'navigation-drawer--right': this.right,
8583
'navigation-drawer--temporary': this.temporary,
8684
'theme--dark': this.dark,
@@ -104,14 +102,24 @@ export default {
104102
? this.$vuetify.application.top + this.$vuetify.application.bottom
105103
: this.$vuetify.application.bottom
106104
},
107-
reactsToMobile () {
105+
reactsToClick () {
108106
return !this.stateless &&
109-
!this.disableResizeWatcher &&
110-
this.isBooted &&
107+
!this.permanent &&
108+
(this.isMobile || this.temporary)
109+
},
110+
reactsToMobile () {
111+
return !this.disableResizeWatcher &&
112+
!this.stateless &&
113+
!this.permanent &&
111114
!this.temporary
112115
},
113116
reactsToRoute () {
114-
return !this.disableRouteWatcher && !this.stateless
117+
return !this.disableRouteWatcher &&
118+
!this.stateless &&
119+
!this.permanent
120+
},
121+
resizeIsDisabled () {
122+
return this.disableResizeWatcher || this.stateless
115123
},
116124
showOverlay () {
117125
return this.isActive &&
@@ -136,12 +144,10 @@ export default {
136144
isActive (val) {
137145
this.$emit('input', val)
138146

139-
if (!this.isBooted ||
140-
(!this.temporary && !this.isMobile)
141-
) return
142-
143-
this.tryOverlay()
144-
this.$el.scrollTop = 0
147+
if (this.temporary || this.isMobile) {
148+
this.tryOverlay()
149+
this.$el.scrollTop = 0
150+
}
145151
},
146152
/**
147153
* When mobile changes, adjust
@@ -150,24 +156,21 @@ export default {
150156
* value
151157
*/
152158
isMobile (val, prev) {
153-
!val && this.isActive && this.removeOverlay()
159+
!val &&
160+
this.isActive &&
161+
!this.temporary &&
162+
this.removeOverlay()
154163

155-
if (!this.reactsToMobile) return
164+
if (prev == null ||
165+
this.resizeIsDisabled
166+
) return
156167

157-
if (prev != null && !this.temporary) {
158-
this.isActive = !val
159-
}
168+
this.isActive = !val
160169
},
161170
permanent (val) {
162-
// If we are removing prop
163-
// reset active to match
164-
// current value
165-
if (!val) return (this.isActive = this.value)
166-
167-
// We are enabling prop
168-
// set its state to match
169-
// viewport size
170-
this.isActive = !this.isMobile
171+
// If enabling prop
172+
// enable the drawer
173+
if (val) this.isActive = true
171174
},
172175
right (val, prev) {
173176
// When the value changes
@@ -180,34 +183,27 @@ export default {
180183
this.updateApplication()
181184
},
182185
temporary (val) {
183-
if (!val) return
184-
185186
this.tryOverlay()
186187
},
187188
value (val) {
188-
if (this.permanent && !this.isMobile) return
189+
if (this.permanent) return
190+
189191
if (val !== this.isActive) this.isActive = val
190192
}
191193
},
192194

193-
mounted () {
195+
beforeMount () {
194196
this.checkIfMobile()
195197

196-
// Same as 3rd conditional
197-
// but has higher precedence
198-
// than simply providing
199-
// a default value
200-
if (this.stateless) {
201-
this.isActive = this.value
202-
} else if (this.permanent && !this.isMobile) {
198+
if (this.permanent) {
203199
this.isActive = true
204-
} else if (this.value != null) {
200+
} else if (this.stateless ||
201+
this.value != null
202+
) {
205203
this.isActive = this.value
206204
} else if (!this.temporary) {
207205
this.isActive = !this.isMobile
208206
}
209-
210-
setTimeout(() => (this.isBooted = true), 0)
211207
},
212208

213209
destroyed () {
@@ -227,10 +223,14 @@ export default {
227223
}
228224
},
229225
checkIfMobile () {
226+
if (this.permanent ||
227+
this.temporary
228+
) return
229+
230230
this.isMobile = window.innerWidth < parseInt(this.mobileBreakPoint, 10)
231231
},
232232
closeConditional () {
233-
return !this.stateless && (this.isMobile || this.temporary)
233+
return this.reactsToClick
234234
},
235235
genDirectives () {
236236
const directives = [
@@ -280,7 +280,10 @@ export default {
280280
else if (!this.right && this.isActive) this.isActive = false
281281
},
282282
tryOverlay () {
283-
if (this.showOverlay && this.isActive) {
283+
if (!this.permanent &&
284+
this.showOverlay &&
285+
this.isActive
286+
) {
284287
return this.genOverlay()
285288
}
286289

@@ -290,8 +293,8 @@ export default {
290293
if (!this.app) return
291294

292295
const width = !this.isActive ||
293-
this.isMobile ||
294-
this.temporary
296+
this.temporary ||
297+
this.isMobile
295298
? 0
296299
: this.calculatedWidth
297300

0 commit comments

Comments
 (0)