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

feat(aio): scrolling tweaks per PR#16619 #16660

Merged
merged 1 commit into from May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion aio/src/app/app.component.html
Expand Up @@ -24,7 +24,7 @@
</md-sidenav>

<section class="sidenav-content" [id]="pageId" role="content">
<a id="top-of-page"></a>
<div id="top-of-page"></div>
<aio-doc-viewer [doc]="currentDocument" (docRendered)="onDocRendered()"></aio-doc-viewer>
<aio-dt [on]="dtOn" [(doc)]="currentDocument"></aio-dt>
</section>
Expand Down
2 changes: 1 addition & 1 deletion aio/src/app/embedded/toc/toc.component.html
@@ -1,7 +1,7 @@
<div *ngIf="hasToc" [class.closed]="isClosed">
<div *ngIf="!hasSecondary" class="toc-heading">Contents</div>
<div *ngIf="hasSecondary" class="toc-heading secondary"
(click)="toggle()"
(click)="toggle(false)"
title="Expand/collapse contents"
aria-label="Expand/collapse contents">
<p>Table of Contents<button type="button" class="toc-show-all material-icons" [class.closed]="isClosed"></button></p>
Expand Down
20 changes: 7 additions & 13 deletions aio/src/app/embedded/toc/toc.component.spec.ts
Expand Up @@ -178,16 +178,10 @@ describe('TocComponent', () => {
expect(tocComponent.isClosed).toEqual(true);
});

it('should scroll after clicking again', () => {
it('should not scroll after clicking again', () => {
page.tocHeadingButton.nativeElement.click();
fixture.detectChanges();
expect(scrollSpy).toHaveBeenCalled();
});

it('should be "closed" after clicking tocMoreButton', () => {
page.tocMoreButton.nativeElement.click();
fixture.detectChanges();
expect(tocComponent.isClosed).toEqual(true);
expect(scrollSpy).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -216,16 +210,16 @@ describe('TocComponent', () => {
expect(tocComponent.isClosed).toEqual(true);
});

it('should scroll after clicking again', () => {
it('should be "closed" after clicking tocHeadingButton', () => {
page.tocMoreButton.nativeElement.click();
fixture.detectChanges();
expect(scrollSpy).toHaveBeenCalled();
expect(tocComponent.isClosed).toEqual(true);
});

it('should be "closed" after clicking tocHeadingButton', () => {
page.tocHeadingButton.nativeElement.click();
it('should scroll after clicking again', () => {
page.tocMoreButton.nativeElement.click();
fixture.detectChanges();
expect(tocComponent.isClosed).toEqual(true);
expect(scrollSpy).toHaveBeenCalled();
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions aio/src/app/embedded/toc/toc.component.ts
Expand Up @@ -51,8 +51,8 @@ export class TocComponent implements OnInit, OnDestroy {
this.onDestroy.next();
}

toggle() {
toggle(canScroll = true) {
this.isClosed = !this.isClosed;
if (this.isClosed) { this.scrollService.scrollToTop(); }
if (canScroll && this.isClosed) { this.scrollService.scrollToTop(); }
}
}
2 changes: 1 addition & 1 deletion aio/src/app/shared/scroll.service.ts
@@ -1,4 +1,4 @@
import { Injectable, Inject, InjectionToken } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { PlatformLocation } from '@angular/common';
import { DOCUMENT } from '@angular/platform-browser';

Expand Down