Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

feat(nav): new sidenav #300

Merged
merged 8 commits into from
Oct 30, 2017
Merged

feat(nav): new sidenav #300

merged 8 commits into from
Oct 30, 2017

Conversation

amcdnl
Copy link
Contributor

@amcdnl amcdnl commented Oct 19, 2017

Implements new sidenav.

img

img

img

@amcdnl amcdnl self-assigned this Oct 19, 2017
@amcdnl amcdnl requested a review from jelbourn October 19, 2017 15:09
Copy link
Contributor

@willshowell willshowell left a comment

Choose a reason for hiding this comment

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

Very excited for this!

$background: map-get($theme, background);
$foreground: map-get($theme, foreground);
$sidenav: '.docs-component-viewer-sidenav';
$is-dark-theme: map-get($theme, is-dark);
$nav-background-color: if($is-dark-theme, 0.2, 0.03);
Copy link
Contributor

Choose a reason for hiding this comment

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

$nav-background-opacity?

</a>
</li>
</ul>
<hr *ngIf="docItems.getCategories((params | async)?.section).length !== (i + 1)" />
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using last so you don't have to sub twice,

<nav *ngFor="let category of docItems.getCategories((params | async)?.section); let last = last;">

  <!-- ... -->

  <hr *ngIf="!last" />
</nav>

@@ -2,25 +2,20 @@

app-component-viewer {
font-weight: 400;
padding: 20px $content-padding-side 50px;
padding: 20px 50px 50px 20px;
Copy link
Contributor

@willshowell willshowell Oct 20, 2017

Choose a reason for hiding this comment

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

Maybe add a comment? Better yet, I see 20px, 25px, 50px coming up a lot. Could they be added to _constants.scss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a search and didn't find any other cases, can you point me to the other usages?

Copy link
Contributor

Choose a reason for hiding this comment

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

I may have said that prematurely. I'll take a look when I get a chance to run it locally. Or I'll try to add sass constants throughout the app in a later PR.

private _router: Router) { }

ngOnInit() {
this._router.events.subscribe(() => this.setExpansions());
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this create a ton of never-completing subscriptions? How about,

ngOnInit() {
  this._router.events
    .switchMap(() => this.params)
    .takeUntil(this._onDestroy)
    .subscribe(p => this.setExpansions(p));
}

ngOnDestroy() {
  this._onDestroy.next();
  this._onDestroy.complete();
}

setExpansions(p: Params) {
  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Thanks for the suggestion!!


.docs-component-sidenav-body-content {
display: flex;
min-height: calc(100vh - 264px);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is 264? It looks based on $sidenav-width somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

264 is the footer + header nav height.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah lol of course the min-height doesn't have anything to do with sidenav width. Maybe add it as a variable with a comment?

Copy link
Member

Choose a reason for hiding this comment

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

Comment for sure at the least

setExpansions() {
this.params.subscribe(p => {
const categories = this.docItems.getCategories(p.section);
for (const category of categories) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a followup of a previous comment, this should be,

setExpansions(p: Params) {
  const categories = this.docItems.getCategories(p.section);
  for (...) {
    // ...
  }
}

so that it doesn't create another subscription. That also means that ngOnInit should updated like,

ngOnInit() {
  this._router.events
    .switchMap(() => this.params)
    .takeUntil(this._onDestroy)
    .subscribe(p => this.setExpansions(p));
}

If there is a problem that _router.events doesn't fire immediately, you could do this,

ngOnInit() {
  this._router.events
    .startWith(null)
    .switchMap(() => this.params)
    .takeUntil(this._onDestroy)
    .subscribe(p => this.setExpansions(p));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Beautiful and done.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

  • Should the page have a minimum height so that it doesn't shrink when all of the sections are collapsed?
  • Any thoughts on adding an expand-all?
  • The click target for the links in the nav should stretch the entire width of the container


.docs-component-viewer-nav-inner {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a more descriptive name than inner, or a comment you could add to explain what the element is?

<div class="docs-component-viewer-nav">
<div class="docs-component-viewer-nav-inner">
<nav *ngFor="let category of docItems.getCategories((params | async)?.section); let last = last;">
<h3 (click)="toggleExpand(category.id)">
Copy link
Member

Choose a reason for hiding this comment

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

For a11y, each of these sections needs to act like an expansion panel. This means that the thing you interact with should be a <button> (with the same aria attrs that expansion panel uses). We shouldn't need to use a real heading element here since it's not part of the document content (table of contents).

</nav>
<app-component-nav
[params]="params">
</app-component-nav>
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it could fit on one line

<app-footer></app-footer>
<div class="docs-component-sidenav-inner-content">
<div class="docs-component-sidenav-body-content">
<app-component-nav
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment explaining the different structure based on screen size?

display: block;
overflow: hidden;
position: absolute;
top: 50px;
Copy link
Member

Choose a reason for hiding this comment

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

Comment for 50px?


.docs-component-sidenav-body-content {
display: flex;
min-height: calc(100vh - 264px);
Copy link
Member

Choose a reason for hiding this comment

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

Comment for sure at the least

@media (max-width: $small-breakpoint-width) {
// Add specific rule to prevent default rule conflict
.docs-component-viewer-sidenav-container .docs-component-viewer-sidenav {
top: 42px;
Copy link
Member

Choose a reason for hiding this comment

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

Comment for 42px?

@@ -1,12 +1,14 @@
:host {
font-size: 13px;
width: 15%;
width: 19%;
Copy link
Member

Choose a reason for hiding this comment

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

Comment?

this._onDestroy.complete();
}

setExpansions(params: Params) {
Copy link
Member

Choose a reason for hiding this comment

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

JsDoc for methods?

@amcdnl
Copy link
Contributor Author

amcdnl commented Oct 23, 2017

Should the page have a minimum height so that it doesn't shrink when all of the sections are collapsed?

That is handled by the 100vh calc above.

Any thoughts on adding an expand-all?

I haven't seen any other pages on Google have this, open to it if you have an idea how to.

The click target for the links in the nav should stretch the entire width of the container.

done.

package.json Outdated
@@ -4,7 +4,7 @@
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "npm run build-themes && ng serve --aot --sourcemaps=false",
Copy link
Member

Choose a reason for hiding this comment

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

--aot

Want to add another command like start-jit that is set up that way?

<div class="docs-component-viewer-nav">
<div class="docs-component-viewer-nav-content">
<nav *ngFor="let category of docItems.getCategories((params | async)?.section); let last = last;">
<button (click)="toggleExpand(category.id)">
Copy link
Member

Choose a reason for hiding this comment

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

  • Add an aria-label like "Expand the {{category.name}} section of navigation links"
  • Add aria-controls pointing to the element that expands
  • Add aria-expanded

@amcdnl
Copy link
Contributor Author

amcdnl commented Oct 23, 2017

@jelbourn - done :)

<div class="docs-component-viewer-nav-content">
<nav *ngFor="let category of docItems.getCategories((params | async)?.section); let last = last;">
<button (click)="toggleExpand(category.id)"
[attr.aria-label]="'Expand the ' + category.name"
Copy link
Member

@jelbourn jelbourn Oct 28, 2017

Choose a reason for hiding this comment

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

I tried this out with VoiceOver. The label would be easier to understand as:
category.name + ', section toggle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn merged commit f1ddeae into angular:master Oct 30, 2017
@amcdnl amcdnl deleted the new-sidenav branch October 30, 2017 17:26
jelbourn added a commit that referenced this pull request Oct 30, 2017
@jelbourn
Copy link
Member

@amcdnl can you re-create this PR? I reverted it b/c it conflicts with a change Miles was working on that will change the structure of the sidenav first

amcdnl added a commit to amcdnl/material.angular.io that referenced this pull request Oct 30, 2017
amcdnl pushed a commit to amcdnl/material.angular.io that referenced this pull request Oct 30, 2017
@amcdnl
Copy link
Contributor Author

amcdnl commented Oct 30, 2017

@mmalerba - let me know when your ready for me to cut a new PR.

@mmalerba
Copy link
Collaborator

@amcdnl my change is merged now

@amcdnl amcdnl mentioned this pull request Nov 1, 2017
@amcdnl
Copy link
Contributor Author

amcdnl commented Nov 1, 2017

Done. See #310

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants