From 966eb2fbd0e270d73d53101f2e61f484e190d4d6 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 24 May 2017 21:09:55 +0100 Subject: [PATCH] aio: add h1 title to floating table of contents (#16959) * refactor(aio): use explicit CSS class for TOC container This makes the styling less fragile to changes in the HTML * fix(aio): schedule TocComponent.activeIndex updates via AsapScheduler We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, which, in turn, are caused by the rendering that happened due to a ChangeDetection. Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular. * refactor(aio): do not instantiate floating ToC if not displayed * feat(aio): display the h1 at the top of the floating TOC Closes #16900 * refactor(aio): combine the TOC booleans flags into a "type" state * refactor(aio): remove unnecessary `hostElement` property * fix(aio): ensure that transition works on TOC * fix(aio): use strict equality in ToC template --- aio/src/app/app.component.html | 4 +- aio/src/app/app.component.spec.ts | 7 + aio/src/app/app.component.ts | 5 + aio/src/app/embedded/toc/toc.component.html | 24 +-- .../app/embedded/toc/toc.component.spec.ts | 150 ++++++++---------- aio/src/app/embedded/toc/toc.component.ts | 42 ++--- aio/src/app/shared/toc.service.spec.ts | 52 +++--- aio/src/app/shared/toc.service.ts | 3 +- aio/src/styles/2-modules/_toc.scss | 33 ++-- 9 files changed, 164 insertions(+), 156 deletions(-) diff --git a/aio/src/app/app.component.html b/aio/src/app/app.component.html index 96508b6f66..f46fa75a16 100644 --- a/aio/src/app/app.component.html +++ b/aio/src/app/app.component.html @@ -35,9 +35,7 @@ - - -
+
diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index e6d37a15d2..7388c4f7ca 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -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', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index d6fce32237..f23eb9c41a 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -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() { @@ -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']) diff --git a/aio/src/app/embedded/toc/toc.component.html b/aio/src/app/embedded/toc/toc.component.html index 9bc80a615e..df1b891bc7 100644 --- a/aio/src/app/embedded/toc/toc.component.html +++ b/aio/src/app/embedded/toc/toc.component.html @@ -1,11 +1,11 @@ -
- +
-
Contents
+
+ Contents +
-
    -
  • - -
  • + +
  • + +
  • +
-