refactor(toc): use cdkScrollable for scrolling, remove unnecessary inputs#321
refactor(toc): use cdkScrollable for scrolling, remove unnecessary inputs#321willshowell wants to merge 9 commits intoangular:mainfrom
Conversation
| if (target) { | ||
| target.scrollIntoView(); | ||
| } | ||
| contentReady(): void { |
There was a problem hiding this comment.
I'd rather name this method for what it does rather than when it's called
| } | ||
| /** Find the target from the url fragment and scroll it into view. */ | ||
| private scrollFragmentIntoView(): void { | ||
| this._ngZone.runTask(() => { |
There was a problem hiding this comment.
Why does this need to enter the zone if it's only updating the scroll position?
There was a problem hiding this comment.
Oops that was leftover from debugging something else. Removed.
| this._ngZone.runTask(() => { | ||
| const target = document.getElementById(this._urlFragment); | ||
| if (target) { | ||
| // scrollIntoView may require next macrotask if target has just been loaded |
There was a problem hiding this comment.
I don't quite follow why this is necessary; the document-viewer knows exactly when the content is loaded and in the DOM
There was a problem hiding this comment.
Without it, scroll position would always end up at the top of the page (can be seen here).
However I now recall that there was some other component that manually updates the scroll position. I'll try to track down any sort of race condition occurring there.
There was a problem hiding this comment.
Yeah it's conflicting with the navigation focus directive,
EDIT: actually not so sure
EDIT 2: It was the component overview doing the auto focus, not the navigation focus directive
d748a50 to
5ad187b
Compare
|
@jelbourn ready for another review. The component overview and component api components were autofocusing the visually hidden element at the top after 100ms. I've changed them to wait until the content has loaded, but before the TOC scrolls the correct header into view. Would it be better for a11y to place focus on the header link when the fragment does exist? |
|
@willshowell Yeah, if there is a fragment then the autofocus should be on the header for that fragment. I think that was just an oversight when doing the autofocus. Would you be interested in addressing that in this PR? |
|
@jelbourn Ugh I thought I'd be able to easily, but I'm hitting some strange behavior where |
|
@amcdnl can you review? |
amcdnl
left a comment
There was a problem hiding this comment.
Looks good overall, just one suggestion for lettables.
| import {Observable} from 'rxjs/Observable'; | ||
| import {ScrollDispatcher, CdkScrollable} from '@angular/cdk/scrolling'; | ||
| import {Subject} from 'rxjs/Subject'; | ||
| import 'rxjs/add/operator/filter'; |
There was a problem hiding this comment.
Lets use Rx Lettables here. I have a PR to transform the rest of them in the app.
… subscribing to events on container - Remove links as an input - Calculate container from scrollable event instead of using input
- Unfortunately seems to require setTimeout... Postponing to next microtask does not work (Promise.resolve)
5ad187b to
0369155
Compare
_activeLinkIndexto ensure only a single link is active at a time (removesactivefrom link interface)linksNote: this still does not work for toc on the guides pages. I thought scrolling would be on the window and therefore be picked up by the scroll dispatcher, but that does not seem to be the case.
cc @jelbourn