Repository navigation
feat(aio): scroll back to top when TOC more-items clicked to close - #16619
Conversation
|
The angular.io preview for 30e89230673c38f00c941c62edc988d2fb0b2796 is available here. |
There was a problem hiding this comment.
👎 for scroll parentElement. IMO, the resulting behavior is more disorienting than helpful. I would expect to scroll the hostElement itself into view.
There was a problem hiding this comment.
I tried that first. Didn't work well. Did you try it?
There was a problem hiding this comment.
I did. What do you mean by "didn't work well"? What happened?
There was a problem hiding this comment.
-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.
30e8923 to
b4844e6
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
How do you like me now, @gkalpak ? |
|
The angular.io preview for b4844e63f0c868ec7486f64d2f83a4ced9e93956 is available here. |
Refactor inspired by @gkalpak feedback on PR angular#16619
b4844e6 to
bb1158a
Compare
There was a problem hiding this comment.
💯
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'; | |||
| private get topOffset() { | ||
| if (!this._topOffset) { | ||
| const toolbar = document.querySelector('md-toolbar.app-toolbar'); | ||
| this._topOffset = (toolbar ? toolbar.clientHeight : 0) + topMargin; |
| </md-sidenav> | ||
|
|
||
| <section class="sidenav-content" [id]="pageId" role="content"> | ||
| <a id="top-of-page"></a> |
There was a problem hiding this comment.
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(); } |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
k. It added some complexity but does take a worry off the table.
|
See follow-up in PR #16660 |
Refactor inspired by @gkalpak feedback on PR angular#16619
Refactor inspired by @gkalpak feedback on PR angular#16619
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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