9
9
-->
10
10
11
11
<template >
12
- <div class =" adjustable-sidebar-width" >
12
+ <div
13
+ class =" adjustable-sidebar-width"
14
+ :class =" {
15
+ dragging: isDragging,
16
+ 'sidebar-hidden': hiddenOnLarge
17
+ }"
18
+ >
13
19
<div
14
20
ref =" sidebar"
15
21
class =" sidebar"
19
25
:style =" asideStyles"
20
26
class =" aside"
21
27
ref =" aside"
22
- @transitionstart =" isTransitioning = true"
23
- @transitionend =" isTransitioning = false"
28
+ :aria-hidden =" hiddenOnLarge ? 'true': null"
29
+ @transitionstart =" trackTransitionStart"
30
+ @transitionend =" trackTransitionEnd"
24
31
>
25
32
<slot
26
33
name =" aside"
35
42
@touchstart.prevent =" startDrag"
36
43
/>
37
44
</div >
38
- <div class =" content" >
45
+ <div class =" content" ref = " content " >
39
46
<slot />
40
47
</div >
41
48
<BreakpointEmitter :scope =" BreakpointScopes.nav" @change =" breakpoint = $event" />
@@ -96,8 +103,13 @@ export default {
96
103
components: {
97
104
BreakpointEmitter,
98
105
},
106
+ inject: [' store' ],
99
107
props: {
100
- openExternally: {
108
+ shownOnMobile: {
109
+ type: Boolean ,
110
+ default: false ,
111
+ },
112
+ hiddenOnLarge: {
101
113
type: Boolean ,
102
114
default: false ,
103
115
},
@@ -149,12 +161,13 @@ export default {
149
161
' --app-height' : ` ${ windowHeight} px` ,
150
162
}),
151
163
asideClasses: ({
152
- isDragging, openExternally , noTransition, isTransitioning, mobileTopOffset,
164
+ isDragging, shownOnMobile , noTransition, isTransitioning, hiddenOnLarge , mobileTopOffset,
153
165
}) => ({
154
166
dragging: isDragging,
155
- ' force-open' : openExternally,
167
+ ' show-on-mobile' : shownOnMobile,
168
+ ' hide-on-large' : hiddenOnLarge,
156
169
' no-transition' : noTransition,
157
- animating : isTransitioning,
170
+ ' sidebar-transitioning ' : isTransitioning,
158
171
' has-mobile-top-offset' : mobileTopOffset,
159
172
}),
160
173
scrollLockID : () => SCROLL_LOCK_ID ,
@@ -175,7 +188,7 @@ export default {
175
188
window .removeEventListener (' resize' , this .storeWindowSize );
176
189
window .removeEventListener (' orientationchange' , this .storeWindowSize );
177
190
window .removeEventListener (' scroll' , this .storeTopOffset );
178
- if (this .openExternally ) {
191
+ if (this .shownOnMobile ) {
179
192
this .toggleScrollLock (false );
180
193
}
181
194
if (this .focusTrapInstance ) this .focusTrapInstance .destroy ();
@@ -208,7 +221,13 @@ export default {
208
221
// re-apply transitions
209
222
this .noTransition = false ;
210
223
},
211
- openExternally: ' handleExternalOpen' ,
224
+ shownOnMobile: ' handleExternalOpen' ,
225
+ isTransitioning (value ) {
226
+ if (! value) this .updateContentWidthInStore ();
227
+ },
228
+ hiddenOnLarge () {
229
+ this .isTransitioning = true ;
230
+ },
212
231
},
213
232
methods: {
214
233
getWidthInCheck: debounce (function getWidthInCheck () {
@@ -226,10 +245,11 @@ export default {
226
245
await this .$nextTick ();
227
246
this .windowWidth = window .innerWidth ;
228
247
this .windowHeight = window .innerHeight ;
248
+ this .updateContentWidthInStore ();
229
249
}, 100 ),
230
250
closeMobileSidebar () {
231
- if (! this .openExternally ) return ;
232
- this .$emit (' update:openExternally ' , false );
251
+ if (! this .shownOnMobile ) return ;
252
+ this .$emit (' update:shownOnMobile ' , false );
233
253
},
234
254
startDrag ({ type }) {
235
255
this .isTouch = type === ' touchstart' ;
@@ -254,8 +274,18 @@ export default {
254
274
if (newWidth > this .maxWidth ) {
255
275
newWidth = this .maxWidth ;
256
276
}
277
+ // calculate the forceClose cutoff point
278
+ const forceCloseCutoff = this .minWidth / 2 ;
279
+ // if we are going beyond the cutoff point and we are closed, open the navigator
280
+ if (this .hiddenOnLarge && newWidth >= forceCloseCutoff) {
281
+ this .$emit (' update:hiddenOnLarge' , false );
282
+ }
257
283
// prevent from shrinking too much
258
284
this .width = Math .max (newWidth, this .minWidth );
285
+ // if the new width is smaller than the cutoff point, force close the nav
286
+ if (newWidth <= forceCloseCutoff) {
287
+ this .$emit (' update:hiddenOnLarge' , true );
288
+ }
259
289
},
260
290
/**
261
291
* Stop the dragging upon mouse up
@@ -273,6 +303,7 @@ export default {
273
303
},
274
304
emitEventChange (width ) {
275
305
this .$emit (' width-change' , width);
306
+ this .updateContentWidthInStore ();
276
307
},
277
308
getTopOffset () {
278
309
const stickyNavAnchor = document .getElementById (baseNavStickyAnchorId);
@@ -286,6 +317,10 @@ export default {
286
317
}
287
318
this .toggleScrollLock (isOpen);
288
319
},
320
+ async updateContentWidthInStore () {
321
+ await this .$nextTick ();
322
+ this .store .setContentWidth (this .$refs .content .offsetWidth );
323
+ },
289
324
/**
290
325
* Toggles the scroll lock on/off
291
326
*/
@@ -307,6 +342,16 @@ export default {
307
342
storeTopOffset: throttle (function storeTopOffset () {
308
343
this .topOffset = this .getTopOffset ();
309
344
}, 60 ),
345
+ trackTransitionStart ({ propertyName }) {
346
+ if (propertyName === ' width' || propertyName === ' transform' ) {
347
+ this .isTransitioning = true ;
348
+ }
349
+ },
350
+ trackTransitionEnd ({ propertyName }) {
351
+ if (propertyName === ' width' || propertyName === ' transform' ) {
352
+ this .isTransitioning = false ;
353
+ }
354
+ },
310
355
},
311
356
};
312
357
</script >
@@ -320,6 +365,14 @@ export default {
320
365
display : block ;
321
366
position : relative ;
322
367
}
368
+
369
+ & .dragging /deep / * {
370
+ cursor : col-resize !important ;
371
+ }
372
+
373
+ & .sidebar-hidden.dragging /deep / * {
374
+ cursor : e-resize !important ;
375
+ }
323
376
}
324
377
325
378
.sidebar {
@@ -339,6 +392,22 @@ export default {
339
392
transition : none !important ;
340
393
}
341
394
395
+ @include breakpoints-from (large , nav ) {
396
+
397
+ & :not (.dragging ) {
398
+ transition : width $adjustable-sidebar-hide-transition-duration ease-in ,
399
+ visibility 0s linear 0s ;
400
+ }
401
+
402
+ & .hide-on-large {
403
+ width : 0 !important ;
404
+ visibility : hidden ;
405
+ pointer-events : none ;
406
+ transition : width $adjustable-sidebar-hide-transition-duration ease-in ,
407
+ visibility 0s linear $adjustable-sidebar-hide-transition-duration ;
408
+ }
409
+ }
410
+
342
411
@include breakpoint (medium , nav ) {
343
412
width : 100% !important ;
344
413
overflow : hidden ;
@@ -348,15 +417,15 @@ export default {
348
417
position : fixed ;
349
418
top : var (--top-offset-mobile );
350
419
bottom : 0 ;
351
- z-index : $nav-z-index ;
420
+ z-index : $nav-z-index + 1 ;
352
421
transform : translateX (-100% );
353
422
transition : transform 0.15s ease-in ;
354
423
355
424
/deep / .aside-animated-child {
356
425
opacity : 0 ;
357
426
}
358
427
359
- & .force-open {
428
+ & .show-on-mobile {
360
429
transform : translateX (0 );
361
430
362
431
/deep / .aside-animated-child {
0 commit comments