Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aio: add h1 title to floating table of contents #16959

Merged
merged 8 commits into from May 24, 2017
4 changes: 1 addition & 3 deletions aio/src/app/app.component.html
Expand Up @@ -35,9 +35,7 @@

</md-sidenav-container>



<div class="toc-container" [style.max-height.px]="tocMaxHeight">
<div *ngIf="showFloatingToc" class="toc-container" [style.max-height.px]="tocMaxHeight">
<aio-toc></aio-toc>
</div>

Expand Down
7 changes: 7 additions & 0 deletions aio/src/app/app.component.spec.ts
Expand Up @@ -75,6 +75,13 @@ describe('AppComponent', () => {
component.onResize(500);
expect(component.isSideBySide).toBe(false);
});

it('should update `showFloatingToc` accordingly', () => {
component.onResize(801);
expect(component.showFloatingToc).toBe(true);
component.onResize(800);
expect(component.showFloatingToc).toBe(false);
});
});

describe('onScroll', () => {
Expand Down
5 changes: 5 additions & 0 deletions aio/src/app/app.component.ts
Expand Up @@ -65,8 +65,12 @@ export class AppComponent implements OnInit {
sideNavNodes: NavigationNode[];
topMenuNodes: NavigationNode[];
topMenuNarrowNodes: NavigationNode[];

showFloatingToc = false;
showFloatingTocWidth = 800;
tocMaxHeight: string;
private tocMaxHeightOffset = 0;

versionInfo: VersionInfo;

get homeImageUrl() {
Expand Down Expand Up @@ -198,6 +202,7 @@ export class AppComponent implements OnInit {
@HostListener('window:resize', ['$event.target.innerWidth'])
onResize(width) {
this.isSideBySide = width > this.sideBySideWidth;
this.showFloatingToc = width > this.showFloatingTocWidth;
}

@HostListener('click', ['$event.target', '$event.button', '$event.ctrlKey', '$event.metaKey', '$event.altKey'])
Expand Down
24 changes: 13 additions & 11 deletions aio/src/app/embedded/toc/toc.component.html
@@ -1,11 +1,11 @@
<div *ngIf="hasToc" [class.collapsed]="isCollapsed">
<button *ngIf="!isEmbedded" type="button" class="toc-heading"
(click)="toTop()" title="Top of page">Contents</button>
<div *ngIf="type !== 'None'" class="toc-inner" [class.collapsed]="isCollapsed">

<div *ngIf="!hasSecondary && isEmbedded" class="toc-heading embedded">Contents</div>
<div *ngIf="type === 'EmbeddedSimple'" class="toc-heading embedded">
Contents
</div>

<button *ngIf="hasSecondary" type="button" class="toc-heading embedded secondary"
(click)="toggle(false)"
<button *ngIf="type === 'EmbeddedExpandable'" type="button" (click)="toggle(false)"
class="toc-heading embedded secondary"
title="Expand/collapse contents"
aria-label="Expand/collapse contents"
[attr.aria-pressed]="!isCollapsed">
Expand All @@ -14,13 +14,15 @@
</button>

<ul class="toc-list">
<li #tocItem *ngFor="let toc of tocList; let i = index" title="{{toc.title}}"
class="{{toc.level}}" [class.secondary]="toc.isSecondary" [class.active]="i === activeIndex">
<a [href]="toc.href" [innerHTML]="toc.content"></a>
</li>
<ng-container *ngFor="let toc of tocList; let i = index">
<li #tocItem title="{{toc.title}}" *ngIf="type === 'Floating' || toc.level !== 'h1'"
class="{{toc.level}}" [class.secondary]="type === 'EmbeddedExpandable' && i >= primaryMax" [class.active]="i === activeIndex">
<a [href]="toc.href" [innerHTML]="toc.content"></a>
</li>
</ng-container>
</ul>

<button type="button" (click)="toggle()" *ngIf="hasSecondary"
<button *ngIf="type === 'EmbeddedExpandable'" type="button" (click)="toggle()"
class="toc-more-items embedded material-icons" [class.collapsed]="isCollapsed"
title="Expand/collapse contents"
aria-label="Expand/collapse contents"
Expand Down