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

Commit 6d1a377

Browse files
committed
fix(docs-api): tables overflow screen width on mobile
- fix docs-api layouts to work down to 360px width - fixes Observers, Accessibility, Drag and Drop, Platform, and Overlay layouts - fix DeprecatedconnectedTo to Deprecated connectedTo display issue - update footer copyright - fix exception trying to unsubscribe to undefined routeParamSubscription - change how sidenav is closed on mobile after selecting a nav item Fixes #550
1 parent 347c538 commit 6d1a377

File tree

11 files changed

+76
-64
lines changed

11 files changed

+76
-64
lines changed

src/app/pages/component-category-list/component-category-list.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export class ComponentCategoryList implements OnInit, OnDestroy {
3838
}
3939

4040
ngOnDestroy() {
41-
this.routeParamSubscription.unsubscribe();
41+
if (this.routeParamSubscription) {
42+
this.routeParamSubscription.unsubscribe();
43+
}
4244
}
4345
}
4446

src/app/pages/component-sidenav/_component-sidenav-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
border-top: solid 1px rgba(mat-color($foreground, secondary-text), .1)
3232
}
3333

34-
button {
34+
a {
3535
color: mat-color($foreground, secondary-text);
3636

3737
&.docs-component-viewer-sidenav-item-selected,

src/app/pages/component-sidenav/component-nav.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
</button>
1111
<mat-nav-list dense [@bodyExpansion]="panel.expanded ? 'expanded' : 'collapsed'"
1212
id="panel-{{category.id}}" [attr.aria-label]="category.name">
13-
<button mat-list-item *ngFor="let component of category.items"
14-
[ngClass]="{'docs-component-viewer-sidenav-item-selected': currentItemId === component.id}"
15-
[attr.aria-current]="currentItemId === component.id ? 'page': 'false'"
16-
(click)="selectNavItem(component.id)">
13+
<a mat-list-item *ngFor="let component of category.items"
14+
[routerLink]="'/' + (params | async)?.section+ '/' + component.id"
15+
routerLinkActive="docs-component-viewer-sidenav-item-selected"
16+
[attr.aria-current]="currentItemId === component.id ? 'page': 'false'">
1717
{{component.name}}
18-
</button>
18+
</a>
1919
</mat-nav-list>
2020
<hr *ngIf="!last" />
2121
</div>

src/app/pages/component-sidenav/component-sidenav.service.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
1212
import {MatIconModule} from '@angular/material/icon';
1313
import {MatSidenav, MatSidenavModule} from '@angular/material/sidenav';
14-
import {ActivatedRoute, Params, Router, RouterModule, Routes} from '@angular/router';
14+
import {ActivatedRoute, NavigationEnd, Params, Router, RouterModule, Routes} from '@angular/router';
1515
import {CommonModule} from '@angular/common';
1616
import {ComponentHeaderModule} from '../component-page-header/component-page-header';
1717
import {FooterModule} from '../../shared/footer/footer';
1818
import {combineLatest, Observable, Subject} from 'rxjs';
19-
import {map, startWith, switchMap, takeUntil} from 'rxjs/operators';
19+
import {filter, map, startWith, switchMap, takeUntil} from 'rxjs/operators';
2020
import {animate, state, style, transition, trigger} from '@angular/animations';
2121
import {CdkAccordionModule} from '@angular/cdk/accordion';
2222
import {BreakpointObserver} from '@angular/cdk/layout';
@@ -29,18 +29,25 @@ import {
2929
ComponentApi,
3030
ComponentExamples,
3131
ComponentOverview,
32-
ComponentViewer, ComponentViewerModule
32+
ComponentViewer,
33+
ComponentViewerModule
3334
} from '../component-viewer/component-viewer';
3435
import {DocViewerModule} from '../../shared/doc-viewer/doc-viewer-module';
3536
import {FormsModule} from '@angular/forms';
3637
import {HttpClientModule} from '@angular/common/http';
3738
import {StackBlitzButtonModule} from '../../shared/stack-blitz';
3839
import {SvgViewerModule} from '../../shared/svg-viewer/svg-viewer';
3940
import {ExampleModule} from '@angular/components-examples';
40-
import {ComponentSidenavService} from './component-sidenav.service';
4141
import {MatDrawerToggleResult} from '@angular/material/sidenav/drawer';
4242
import {MatListModule} from '@angular/material/list';
4343

44+
// These constants are used by the ComponentSidenav for orchestrating the MatSidenav in a responsive
45+
// way. This includes hiding the sidenav, defaulting it to open, changing the mode from over to
46+
// side, determining the size of the top gap, and whether the sidenav is fixed in the viewport.
47+
// The values were determined through the combination of Material Design breakpoints and careful
48+
// testing of the application across a range of common device widths (360px+).
49+
// These breakpoint values need to stay in sync with the related Sass variables in
50+
// src/styles/_constants.scss.
4451
const EXTRA_SMALL_WIDTH_BREAKPOINT = 720;
4552
const SMALL_WIDTH_BREAKPOINT = 959;
4653

@@ -58,7 +65,7 @@ export class ComponentSidenav implements OnInit {
5865

5966
constructor(public docItems: DocumentationItems,
6067
private _route: ActivatedRoute,
61-
private componentSidenavService: ComponentSidenavService,
68+
private _router: Router,
6269
zone: NgZone,
6370
breakpoints: BreakpointObserver) {
6471
this.isExtraScreenSmall =
@@ -72,11 +79,20 @@ export class ComponentSidenav implements OnInit {
7279
// Combine params from all of the path into a single object.
7380
this.params = combineLatest(
7481
this._route.pathFromRoot.map(route => route.params), Object.assign);
82+
83+
this._router.events.pipe(
84+
filter((event) => event instanceof NavigationEnd),
85+
map((event) => this.isScreenSmall)
86+
).subscribe((shouldCloseSideNav) => {
87+
if (shouldCloseSideNav && this.sidenav) {
88+
this.sidenav.close();
89+
}
90+
}
91+
);
7592
}
7693

7794
toggleSidenav(sidenav: MatSidenav): Promise<MatDrawerToggleResult> {
78-
this.componentSidenavService.sidenav = sidenav;
79-
return this.componentSidenavService.sidenav.toggle();
95+
return sidenav.toggle();
8096
}
8197
}
8298

@@ -97,8 +113,7 @@ export class ComponentNav implements OnInit, OnDestroy {
97113
currentItemId: string;
98114
private _onDestroy = new Subject<void>();
99115

100-
constructor(public docItems: DocumentationItems, private _router: Router,
101-
private componentSidenavService: ComponentSidenavService) {}
116+
constructor(public docItems: DocumentationItems, private _router: Router) {}
102117

103118
ngOnInit() {
104119
this._router.events.pipe(
@@ -147,28 +162,6 @@ export class ComponentNav implements OnInit, OnDestroy {
147162
getExpanded(category: string): boolean {
148163
return this.expansions[category] === undefined ? true : this.expansions[category];
149164
}
150-
151-
/**
152-
* If the component sidenav can be resolved, then close it, and wait for it to be closed,
153-
* before navigating to avoid jank.
154-
* @param path component.id sub-path to use for navigation
155-
*/
156-
selectNavItem(path: string): void {
157-
if (this.componentSidenavService.sidenav) {
158-
this.componentSidenavService.sidenav.close().then(() => this.openNavItem(path));
159-
} else {
160-
this.openNavItem(path);
161-
}
162-
}
163-
164-
/**
165-
* @param path component.id sub-path to use for navigation
166-
*/
167-
openNavItem(path: string) {
168-
this.params.subscribe((params: Params) => {
169-
this._router.navigateByUrl(`/${params.section}/${path}`);
170-
});
171-
}
172165
}
173166

174167
const routes: Routes = [ {

src/app/pages/component-viewer/component-api.html

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
API for {{docItem?.id}}
44
</span>
55

6-
<span>
7-
<doc-viewer
8-
documentUrl="/docs-content/api-docs/{{docItem?.packageName}}-{{docItem?.id}}.html"
9-
class="docs-component-view-text-content docs-component-api"
10-
(contentRendered)="updateTableOfContents(docItem!.name, $event)">
11-
</doc-viewer>
6+
<doc-viewer
7+
documentUrl="/docs-content/api-docs/{{docItem?.packageName}}-{{docItem?.id}}.html"
8+
class="docs-component-view-text-content docs-component-api"
9+
(contentRendered)="updateTableOfContents(docItem!.name, $event)">
10+
</doc-viewer>
1211

13-
<doc-viewer *ngFor="let additionalApiDoc of docItem!.additionalApiDocs"
14-
documentUrl="/docs-content/api-docs/{{additionalApiDoc.path}}"
15-
class="docs-component-view-text-content docs-component-api"
16-
(contentRendered)="updateTableOfContents(additionalApiDoc.name, $event)">
17-
</doc-viewer>
18-
</span>
12+
<doc-viewer *ngFor="let additionalApiDoc of docItem!.additionalApiDocs"
13+
documentUrl="/docs-content/api-docs/{{additionalApiDoc.path}}"
14+
class="docs-component-view-text-content docs-component-api"
15+
(contentRendered)="updateTableOfContents(additionalApiDoc.name, $event)">
16+
</doc-viewer>
1917

2018
<table-of-contents #toc
2119
*ngIf="showToc | async"

src/app/pages/component-viewer/component-api.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
}
1212
}
1313

14+
.docs-api-type-alias-name,
15+
.docs-api-class-name {
16+
@media (max-width: 399px) {
17+
word-break: break-word;
18+
}
19+
}
20+
1421
.docs-api-h3 {
1522
font-weight: 300;
1623
font-size: 24px;

src/app/shared/footer/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<div class="docs-footer-copyright">
2020
<div>
21-
<span>Powered by Google ©2010-2019.</span>
21+
<span>Powered by Google ©2010-2020.</span>
2222
<a href="https://github.com/angular/components/blob/master/LICENSE">Code licensed under an MIT-style License.</a>
2323
<span>Documentation licensed under CC BY 4.0.</span>
2424
</div>

src/styles/_api.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Styles for API docs generated via dgeni from material2 source JsDocs.
22

3+
.docs-api {
4+
max-width: 100%;
5+
}
6+
37
// Top header, e.g., "API documentation for dialog".
48
.docs-api-h2 {
59
font-size: 30px;
@@ -62,6 +66,10 @@
6266
font-size: 12px;
6367
}
6468

69+
.docs-api-deprecated-marker {
70+
margin-right: 8px;
71+
}
72+
6573
.docs-api-module-import,
6674
.docs-api-class-selector-name,
6775
.docs-api-class-export-name {

src/styles/_constants.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
@import '../../node_modules/@angular/material/theming';
22

3+
// The values were determined through the combination of Material Design breakpoints and careful
4+
// testing of the application across a range of common device widths (360px+).
5+
// These breakpoint values need to stay in sync with the related constants in
6+
// src/app/pages/component-sidenav/component-sidenav.ts.
7+
// The extra small breakpoint is used for styling the guides and certain aspects of the tables.
38
$extra-small-breakpoint-width: 720px;
9+
// The small breakpoint is used for the component category and component list pages, the component
10+
// pages, the component sidenav, and certain aspects of the tables.
411
$small-breakpoint-width: 959px;
512

613
/* For desktop, the content should be aligned with the page title. */

src/styles/_tables.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
.docs-markdown-td {
2323
font-weight: 400;
2424
padding: 8px 16px;
25+
26+
@media (max-width: $extra-small-breakpoint-width) {
27+
&.docs-api-properties-name-cell,
28+
&.docs-api-method-parameter-cell,
29+
&.docs-api-method-returns-type-cell,
30+
&.docs-api-method-description-cell {
31+
min-width: 80px;
32+
word-break: break-word;
33+
}
34+
}
2535
}
2636

2737

0 commit comments

Comments
 (0)