Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit b17882a

Browse files
committed
Reset scroll position when the route changes
1 parent 4249a95 commit b17882a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/app/material-docs-app.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ import {Router, NavigationStart} from '@angular/router';
66
selector: 'material-docs-app',
77
templateUrl: './material-docs-app.html',
88
styleUrls: ['./material-docs-app.scss'],
9-
host: {
10-
'[class.docs-dark-theme]': 'isDarkTheme',
11-
},
129
encapsulation: ViewEncapsulation.None,
1310
})
1411
export class MaterialDocsApp {
15-
isDarkTheme = false;
1612
showShadow = false;
1713

18-
constructor(
19-
router: Router,
20-
) {
14+
constructor(router: Router) {
2115
router.events.subscribe((data: NavigationStart) => {
2216
this.showShadow = data.url.startsWith('/components');
17+
resetScrollPosition();
2318
});
2419
}
2520
}
21+
22+
function resetScrollPosition() {
23+
if (typeof document === 'object' && document) {
24+
const sidenavContent = document.querySelector('.mat-sidenav-content');
25+
if (sidenavContent) {
26+
sidenavContent.scrollTop = 0;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)