Repository navigation
Teach directives with a lesson nav - #41
Merged
Merged
Conversation
Every lesson should get an "On this page" nav over its sections that marks the one in view. ScrollSpy, LessonSection and lesson 10 don't exist yet; the every-lesson spec fails nine times with no nav at all.
LessonSection matches each h2 in a lesson, gives it an id from its text and registers it with ScrollSpy, which the lesson component takes as a host directive. ScrollSpy creates its IntersectionObserver in afterNextRender, so prerender never touches it, and highlights the section in view. The lesson spec's scrollIntoView mock needed a type.
The tag page spec assumed every guide title starts "Angular 0", which stopped being true at lesson 10; it now matches two digits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tenth lesson in my Angular guide: directives. The feature slice is an "On this page" nav on every lesson. It jumps to a section and highlights the one in view.
What shipped
A nav on every lesson.
tabindex="-1".aria-current="location".prefers-reduced-motion; browsers don't do that on their own.<base href="/">,href="#simple"resolves to/#simple, androuterLinkwould need a router in every lesson spec.ScrollSpy(lessons/scroll-spy.ts). An attribute directive that owns anIntersectionObserver.afterNextRender, so prerender never sees it, and disconnected throughDestroyRef.Lessontakes it as a host directive, so no lesson writes an attribute for it.LessonSection(lessons/lesson-section.ts). A directive with selectorh2, the same trickNgFormuses on<form>.ScrollSpyit injects. Element injectors follow the template, so a heading projected into<app-lesson>finds it.Lessonlists the headings withcontentChildren, so the nav and the ids are in the prerendered HTML.Lesson 10: directives (
/thoughts/angular-10-directives).*desugaringTemplateRef/ViewContainerRefand ahostDirectiveschip with a renamed input.Version and changelog. 1.4.9, with a matching changelog entry.
Commits
Verification
ScrollSpy,Lessonand lesson 10 specs didn't compile.scrollIntoViewmock inlesson.spec.tsneeded its real type.app.routes.spec.tsassumed every guide title starts "Angular 0", which stopped being true at lesson 10. It now matches two digits.ng test: 64 files, 451 tests, exit 0. That includes theScrollSpyunit specs against a fakeIntersectionObserver, the nav on all ten lessons, and axe on the nav and the lesson 10 demos.tsc --noEmitconfigs are clean.simple,intermediate,expert,pitfallsandinterview-questions.@angular/corechunk: this is the first use ofcontentChildren,hostDirectivesandafterNextRender, and core ships as one flat module.TO-DOs for this PR