@@ -301,13 +301,59 @@ watch(focusTrapEnabled, async (enabled: boolean) => {
301
301
}
302
302
}, { immediate: true })
303
303
304
- onMounted (() => {
304
+ // If the user is on a Mac, we may need to add extra padding to the sidebar scroll container
305
+ const scrollbarExtraPadding = ref <string >(' 0px' )
306
+
307
+ /**
308
+ * Determine the width of the user's scrollbar, if on a Mac, based on the `Appearance > Show scroll bars` setting.
309
+ * If the width equals zero, add 8px of extra padding to the .sidebar-content-container.
310
+ * This isn't great and I hate it, but it works ¯\_(ツ)_/¯
311
+ */
312
+ const getScrollbarWidth = (): void => {
313
+ // @ts-ignore Determine if the user is on MacOS
314
+ const isMac = / Mac| iPhone| iPod| iPad/ i .test (navigator ?.platform ) || / macOS| Mac| iPhone| iPod| iPad/ i .test (navigator ?.userAgentData ?.platform )
315
+
316
+ if (! isMac ) {
317
+ return
318
+ }
319
+
320
+ const outerElement = document .createElement (' div' )
321
+ outerElement .style .visibility = ' hidden'
322
+ outerElement .style .width = ' 100px'
323
+ document .body .appendChild (outerElement )
324
+
325
+ const widthNoScroll = outerElement .offsetWidth
326
+ // force scrollbar
327
+ outerElement .style .overflow = ' scroll'
328
+
329
+ // add inner element
330
+ const innerElement = document .createElement (' div' )
331
+ innerElement .style .width = ' 100%'
332
+ outerElement .appendChild (innerElement )
333
+
334
+ const widthWithScroll = innerElement .offsetWidth
335
+
336
+ // remove inner elements
337
+ outerElement .parentNode && outerElement .parentNode .removeChild (outerElement )
338
+
339
+ const scrollbarWidth = widthNoScroll - widthWithScroll
340
+
341
+ if (scrollbarWidth === 0 ) {
342
+ scrollbarExtraPadding .value = ' 8px'
343
+ }
344
+ }
345
+
346
+ onMounted (async () => {
305
347
// Set the window width once the component mounts
306
348
windowWidth .value = window ?.innerWidth
307
349
// Automatically close the sidebar if the window is resized
308
350
window .addEventListener (' resize' , debouncedResizeHandler )
309
351
// Disable mobile sidebar transitions when the window is resized
310
352
window .addEventListener (' resize' , disableTransitions )
353
+
354
+ await nextTick ()
355
+ // Adjust the sidebar padding
356
+ getScrollbarWidth ()
311
357
})
312
358
313
359
onBeforeUnmount (() => {
@@ -368,6 +414,7 @@ onBeforeUnmount(() => {
368
414
overflow-x : hidden ;
369
415
// Must use `scroll` so that the scrollbar width is always accounted for. Cannot use `overlay` here as it breaks in Firefox.
370
416
overflow-y : scroll ;
417
+ padding-right : v-bind (' scrollbarExtraPadding' );
371
418
padding-top : $sidebar-header-spacing ;
372
419
position : relative ;
373
420
width : 100% ;
0 commit comments