Skip to content

Commit 6f11c74

Browse files
authored
Merge pull request #427 from iceljc/main
Fix sidebar menu scrolling
2 parents 23f4dff + 1b7caec commit 6f11c74

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

src/lib/scss/custom/structure/_vertical.scss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@
228228
position: absolute;
229229
width: $sidebar-collapsed-width !important;
230230
z-index: 5;
231+
overflow-y: auto;
232+
scrollbar-width: none;
231233

232234
.simplebar-mask,
233235
.simplebar-content-wrapper {
@@ -242,6 +244,10 @@
242244
bottom: 0 !important;
243245
}
244246

247+
#vertical-menu {
248+
height: auto !important;
249+
}
250+
245251
// Sidebar Menu
246252
#sidebar-menu {
247253

@@ -263,7 +269,7 @@
263269

264270
>ul {
265271
>li {
266-
position: relative;
272+
position: static;
267273
white-space: nowrap;
268274

269275
>a {
@@ -308,7 +314,7 @@
308314
>ul {
309315
display: block;
310316
left: $sidebar-collapsed-width;
311-
position: absolute;
317+
position: fixed;
312318
width: 190px;
313319
height: auto !important;
314320
box-shadow: 3px 5px 10px 0 rgba(54, 61, 71, .1);
@@ -340,13 +346,15 @@
340346
background-color: $sidebar-bg;
341347

342348
li {
349+
position: relative;
350+
343351
&:hover {
344352
>ul {
345353
display: block;
346-
left: 190px;
354+
left: calc(#{$sidebar-collapsed-width} + 190px);
347355
height: auto !important;
348356
margin-top: -36px;
349-
position: absolute;
357+
position: fixed;
350358
width: 190px;
351359
}
352360
}
@@ -417,7 +425,7 @@ body[data-sidebar="dark"] {
417425

418426
// Enlarge menu
419427
&.vertical-collpsed {
420-
min-height: 1760px;
428+
// min-height: 1760px;
421429

422430
// Side menu
423431
.vertical-menu {

src/routes/VerticalLayout/Sidebar.svelte

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
}
7777
7878
activeMenu();
79+
setupCollapsedMenuPositioning();
7980
8081
const curUrl = getCleanUrl($page.url.pathname);
8182
if (curUrl) {
@@ -112,6 +113,41 @@
112113
// menuItemScroll()
113114
});
114115
116+
const setupCollapsedMenuPositioning = () => {
117+
if (!browser) return;
118+
119+
const sideMenu = document.querySelector('#side-menu');
120+
if (!sideMenu) return;
121+
122+
// Position fixed submenus on hover when sidebar is collapsed
123+
sideMenu.querySelectorAll(':scope > li').forEach((li) => {
124+
li.addEventListener('mouseenter', () => {
125+
if (!document.body.classList.contains('vertical-collpsed')) return;
126+
127+
const submenu = li.querySelector(':scope > ul.sub-menu');
128+
if (submenu) {
129+
const rect = li.getBoundingClientRect();
130+
// @ts-ignore
131+
submenu.style.top = `${rect.top}px`;
132+
}
133+
});
134+
});
135+
136+
// Position nested submenus
137+
sideMenu.querySelectorAll('.sub-menu li').forEach((li) => {
138+
li.addEventListener('mouseenter', () => {
139+
if (!document.body.classList.contains('vertical-collpsed')) return;
140+
141+
const nestedSubmenu = li.querySelector(':scope > ul.sub-menu');
142+
if (nestedSubmenu) {
143+
const rect = li.getBoundingClientRect();
144+
// @ts-ignore
145+
nestedSubmenu.style.top = `${rect.top}px`;
146+
}
147+
});
148+
});
149+
};
150+
115151
const activeMenu = () => {
116152
if (browser) {
117153
document.querySelectorAll('.vertical-menu .has-arrow').forEach((menu) => {
@@ -201,7 +237,7 @@
201237
document.body.classList.add('sidebar-enable');
202238
203239
if (menuElement) {
204-
const instance = OverlayScrollbars(menuElement);
240+
const instance = OverlayScrollbars(menuElement, options);
205241
if (instance) {
206242
instance.destroy();
207243
}
@@ -211,7 +247,7 @@
211247
document.body.classList.remove('sidebar-enable');
212248
213249
if (menuElement) {
214-
const instance = OverlayScrollbars(menuElement);
250+
OverlayScrollbars(menuElement, options);
215251
}
216252
}
217253
}

0 commit comments

Comments
 (0)