mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(docs-infra): keep the collapsed code state when a code block is reshown
The code block lives inside `@if (showCode())`, so hiding it destroys the DOM and
showing it builds a fresh copy with no hidden lines. Nothing reapplied
`setCodeLinesVisibility()`, so a collapsed block came back showing the whole file.
Reapply it once the block is rendered again. It already branches on `expanded()`,
so a block that was expanded stays expanded.
(cherry picked from commit 90b9e081f5)
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
[class.docs-example-code-toggle__show]="!showCode()"
|
||||
[attr.aria-checked]="showCode()"
|
||||
[attr.aria-label]="showCode() ? 'Hide code' : 'Show code'"
|
||||
(click)="showCode.set(!showCode())"
|
||||
(click)="toggleCodeVisibility()"
|
||||
[matTooltip]="showCode() ? 'Hide code' : 'Show code'"
|
||||
matTooltipPosition="above"
|
||||
>
|
||||
|
||||
@@ -116,6 +116,15 @@ export class ExampleViewer {
|
||||
this.setCodeLinesVisibility();
|
||||
}
|
||||
|
||||
toggleCodeVisibility(): void {
|
||||
const showCode = !this.showCode();
|
||||
this.showCode.set(showCode);
|
||||
|
||||
if (showCode) {
|
||||
afterNextRender(() => this.setCodeLinesVisibility(), {injector: this.injector});
|
||||
}
|
||||
}
|
||||
|
||||
copyLink(): void {
|
||||
// Reconstruct the URL using `origin + pathname` so we drop any pre-existing hash.
|
||||
const fullUrl =
|
||||
|
||||
Reference in New Issue
Block a user