Skip to content

feat(aio): scroll back to top when TOC more-items clicked to close - #16619

Merged
petebacondarwin merged 2 commits into
angular:masterfrom
IdeaBlade:aio-more-button-scrolls-top
May 9, 2017
Merged

petebacondarwin merged 2 commits into
angular:masterfrom
IdeaBlade:aio-more-button-scrolls-top

Conversation

@wardbell

@wardbell wardbell commented May 7, 2017 •

Copy link
Copy Markdown
Contributor

closes #16482
Usability feature. When long embedded TOC, collapsing it should scroll user to TOC top, not leave in the middle of the page.

Updated to reflect @gkalpak feedback

@gkalpak didn't like the magic scrolling values that were creeping across the app. He didn't like the hokey way I found the element to scroll to when closing the TOC. He was right on all counts.

In curing these defects, I "discovered" that the service was misnamed (it scrolls; it doesn't auto-scroll), and found other opportunities to refactor.


Please check if the PR fulfills these requirements

@wardbell wardbell added comp: aio action: review The PR is still awaiting reviews from at least one requested reviewer labels May 7, 2017
@wardbell wardbell self-assigned this May 7, 2017
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 30e89230673c38f00c941c62edc988d2fb0b2796 is available here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 for scroll parentElement. IMO, the resulting behavior is more disorienting than helpful. I would expect to scroll the hostElement itself into view.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that first. Didn't work well. Did you try it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. What do you mean by "didn't work well"? What happened?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-100 😛
I didn't even like this once in AutoScrollService (which btw scrolls by -80 pixels (which looks better)). Having it duplicated here too...

I would feel much better if we had a reusable scrollToElement helper (or something) that would be used in both places.

closes  angular#16482
Usability feature. When long embedded TOC, collapsing it should scroll user to TOC top, not leave in the middle of the page.
@wardbell
wardbell force-pushed the aio-more-button-scrolls-top branch from 30e8923 to b4844e6 Compare May 8, 2017 23:44

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous omission meant that the tocService was either undefined in this describe block or was the value of the service from the previous describe block. Bad either way. Caught it while implementing these changes.

Comment thread aio/src/app/shared/scroll.service.ts Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed because this service is about scrolling, not "auto-scrolling". In fact, it scrolls imperatively. The "auto" part is how it is used within AppComponent.

@wardbell

wardbell commented May 9, 2017

Copy link
Copy Markdown
Contributor Author

How do you like me now, @gkalpak ?

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for b4844e63f0c868ec7486f64d2f83a4ced9e93956 is available here.

@wardbell
wardbell force-pushed the aio-more-button-scrolls-top branch from b4844e6 to bb1158a Compare May 9, 2017 03:02
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for bb1158a is available here.

@gkalpak gkalpak left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯
LGTM with scrollToTop() fixed (see #16619 (comment)).
(I made a couple other minor subjective suggestions, but feel free to ignore.)

@@ -0,0 +1,70 @@
import { Injectable, Inject, InjectionToken } from '@angular/core';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InjectionToken is unused.

private get topOffset() {
if (!this._topOffset) {
const toolbar = document.querySelector('md-toolbar.app-toolbar');
this._topOffset = (toolbar ? toolbar.clientHeight : 0) + topMargin;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

</md-sidenav>

<section class="sidenav-content" [id]="pageId" role="content">
<a id="top-of-page"></a>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found out that scrolling to this element does not actually scroll to the very top of the page (probably because this is an inline element and thus affected by vertical-align and other styles).

Since there is no need for this to be an <a>, using a block element (e.g. <div>) instead seems to work fine.


toggle() {
this.isClosed = !this.isClosed;
if (this.isClosed) { this.scrollService.scrollToTop(); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense only for the bottom button to trigger scrolling, not the top one. It should be an extra argument passed to toggle() indicating whether scrolling is necessary.
(It is a minor suggestion, since in the vast majority of cases it won't make any difference.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k. It added some complexity but does take a worry off the table.

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 9, 2017
@petebacondarwin
petebacondarwin merged commit 215611a into angular:master May 9, 2017
@wardbell wardbell mentioned this pull request May 9, 2017
2 of 3 tasks
@wardbell

wardbell commented May 9, 2017

Copy link
Copy Markdown
Contributor Author

See follow-up in PR #16660

@wardbell
wardbell deleted the aio-more-button-scrolls-top branch May 9, 2017 18:39
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aio: toc scroll back to top when toc-more-items clicked

5 participants