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

Commit 29469e7

Browse files
devversionjelbourn
authored andcommitted
fix: table of contents not working within cdk (#545)
We intentionally reset the scroll position on navigation if the component view changed (e.g. if you switch from components/button to components/slider). Unfortunately this outdated check causes the CDK ToC to not work. This has been like that for V6 as well. In order to make the ToC work for the CDK, we need to make sure that we don't reset the scroll position if someone navigates within a CDK doc entry.
1 parent c944a1b commit 29469e7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/app/material-docs-app.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ export class MaterialDocsApp {
3030
}
3131
}
3232

33-
function isNavigationWithinComponentView(oldUrl: string, newUrl: string) {
34-
const componentViewExpression = /components\/(\w+)/;
35-
return oldUrl && newUrl
36-
&& componentViewExpression.test(oldUrl)
37-
&& componentViewExpression.test(newUrl)
38-
&& oldUrl.match(componentViewExpression)[1] === newUrl.match(componentViewExpression)[1];
33+
function isNavigationWithinComponentView(previousUrl: string, newUrl: string) {
34+
const componentViewExpression = /(cdk|components)\/(\w+)/;
35+
36+
const previousUrlMatch = previousUrl.match(componentViewExpression);
37+
const newUrlMatch = newUrl.match(componentViewExpression);
38+
39+
return previousUrl && newUrl && previousUrlMatch && newUrlMatch
40+
&& previousUrlMatch[0] === newUrlMatch[0]
41+
&& previousUrlMatch[1] === newUrlMatch[1];
3942
}
4043

4144
function resetScrollPosition() {

0 commit comments

Comments
 (0)