Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit dafda96

Browse files
authored
fix(text-field): Replace MutationObserver + fix validations (#1494)
* Fixed form validation detection * Replaced MutationObserver for SSR support Closes #1486 Closes #1493
1 parent 89d3182 commit dafda96

File tree

25 files changed

+313
-201
lines changed

25 files changed

+313
-201
lines changed

demos/app.module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DialogExampleModule } from './components/dialog-demo/dialog-example.mod
1010

1111
import { AppComponent } from './app.component';
1212
import { AppLayout } from './app-layout';
13+
import { HighlightModule } from 'ngx-highlightjs';
1314

1415
import { APP_ROUTES, DEMO_ROUTES } from './routes';
1516

@@ -21,10 +22,12 @@ import { APP_ROUTES, DEMO_ROUTES } from './routes';
2122
ReactiveFormsModule,
2223
DemoMaterialModule,
2324
DialogExampleModule,
25+
HighlightModule.forRoot({
26+
path: 'assets/highlightjs',
27+
theme: 'github'
28+
}),
2429
RouterModule.forRoot(APP_ROUTES, {
25-
useHash: true,
26-
enableTracing: false,
27-
scrollPositionRestoration: 'enabled'
30+
useHash: true
2831
})
2932
],
3033
declarations: [

demos/assets/highlightjs/highlight.pack.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
3+
github.com style (c) Vasily Polovnyov <[email protected]>
4+
5+
*/
6+
7+
.hljs {
8+
display: block;
9+
overflow-x: auto;
10+
padding: 0.5em;
11+
color: #333;
12+
background: #f8f8f8;
13+
}
14+
15+
.hljs-comment,
16+
.hljs-quote {
17+
color: #998;
18+
font-style: italic;
19+
}
20+
21+
.hljs-keyword,
22+
.hljs-selector-tag,
23+
.hljs-subst {
24+
color: #333;
25+
font-weight: bold;
26+
}
27+
28+
.hljs-number,
29+
.hljs-literal,
30+
.hljs-variable,
31+
.hljs-template-variable,
32+
.hljs-tag .hljs-attr {
33+
color: #008080;
34+
}
35+
36+
.hljs-string,
37+
.hljs-doctag {
38+
color: #d14;
39+
}
40+
41+
.hljs-title,
42+
.hljs-section,
43+
.hljs-selector-id {
44+
color: #900;
45+
font-weight: bold;
46+
}
47+
48+
.hljs-subst {
49+
font-weight: normal;
50+
}
51+
52+
.hljs-type,
53+
.hljs-class .hljs-title {
54+
color: #458;
55+
font-weight: bold;
56+
}
57+
58+
.hljs-tag,
59+
.hljs-name,
60+
.hljs-attribute {
61+
color: #000080;
62+
font-weight: normal;
63+
}
64+
65+
.hljs-regexp,
66+
.hljs-link {
67+
color: #009926;
68+
}
69+
70+
.hljs-symbol,
71+
.hljs-bullet {
72+
color: #990073;
73+
}
74+
75+
.hljs-built_in,
76+
.hljs-builtin-name {
77+
color: #0086b3;
78+
}
79+
80+
.hljs-meta {
81+
color: #999;
82+
font-weight: bold;
83+
}
84+
85+
.hljs-deletion {
86+
background: #fdd;
87+
}
88+
89+
.hljs-addition {
90+
background: #dfd;
91+
}
92+
93+
.hljs-emphasis {
94+
font-style: italic;
95+
}
96+
97+
.hljs-strong {
98+
font-weight: bold;
99+
}

demos/components/dialog-demo/dialog-demo.html

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ <h2>Design & API Documentation</h2>
3535
<tbody>
3636
<tr>
3737
<td>
38-
<pre>open(myDialogComponent)
38+
open(myDialogComponent)
3939

40-
open(myDialogComponent, {{"{
40+
<pre><code highlight code="
41+
open(myDialogComponent, {
4142
id?: string,
4243
ariaDescribedBy?: string,
4344
ariaLabel?: string,
@@ -46,7 +47,7 @@ <h2>Design & API Documentation</h2>
4647
scrollable?: boolean,
4748
buttonsStacked?: boolean,
4849
data?: any
49-
}"}})></pre></td>
50+
})"></code></pre></td>
5051
<td>Opens the dialog with optional configuration.</td>
5152
</tr>
5253
<tr>
@@ -246,83 +247,79 @@ <h3 class="demo-content__headline">Dialog service</h3>
246247
<div class="demo-content">
247248
<h3 class="demo-content__headline">Usage</h3>
248249
A dialog is opened by calling the <code class="docs-markdown-code">open</code> method with a component to be loaded and an optional config object. The <code class="docs-markdown-code">open</code> method will return an instance of <code class="docs-markdown-code">MdcDialogRef</code>:
249-
<pre>
250-
let dialogRef = dialog.open(UserProfileComponent, {{"{
251-
clickOutsideToClose: 'true',
252-
escapeToClose: 'true',
253-
}"}});
254-
</pre>
250+
251+
<pre><code highlight code="let dialogRef = dialog.open(UserProfileComponent, {
252+
clickOutsideToClose: 'true',
253+
escapeToClose: 'true',
254+
});"></code></pre>
255255

256256
The <code class="docs-markdown-code">MdcDialogRef</code> provides a handle on the opened dialog. It can be used to close the dialog and to receive notification when the dialog has been closed.
257-
<pre>
258-
dialogRef.afterClosed().subscribe(result => {{"{
259-
console.log(`Dialog result: ${result}`); // Pizza!
260-
}"}});
261257

262-
dialogRef.close('Pizza!');
263-
</pre>
258+
<pre><code highlight code="dialogRef.afterClosed().subscribe(result => {
259+
console.log(`Dialog result: ${result}`);
260+
});
261+
262+
dialogRef.close('Pizza!');"></code>
263+
</pre>
264264

265265
<p>Components created via <code class="docs-markdown-code">MdcDialog</code> can inject <code class="docs-markdown-code">MdcDialogRef</code> and use it to close the dialog in which they are contained. When closing, an optional result value can be provided. This result value is forwarded as the result of the <code class="docs-markdown-code">afterClosed</code> promise.</p>
266-
<pre>
267-
@Component({{"{/* ... */}"}})
268-
export class YourDialog {{"{
269-
constructor(public dialogRef: MdcDialogRef<![CDATA[<YourDialog>]]>) { }
270266

271-
closeDialog() {
272-
this.dialogRef.close('Pizza!');
273-
}
274-
}"}}
275-
</pre>
267+
<pre><code highlight code="
268+
@Component({/* ... */})
269+
export class YourDialog {
270+
constructor(
271+
dialogRef: MdcDialogRef<YourDialog>) { }
272+
273+
closeDialog() {
274+
this.dialogRef.close('Pizza!');
275+
}
276+
}"></code></pre>
276277

277278
<h3 class="demo-content__headline">Sharing data with the Dialog component</h3>
278279
If you want to share data with your dialog, you can use the <code class="docs-markdown-code">data</code> option to pass information to the dialog component.
279-
<pre>
280-
let dialogRef = dialog.open(YourDialog, {{"{
281-
data: {name: this.name, animal: this.animal}
282-
}"}});
283-
</pre>
280+
281+
<pre>
282+
let dialogRef = dialog.open(YourDialog, {{"{
283+
data: {name: this.name, animal: this.animal}
284+
}"}});
285+
</pre>
284286

285287
To access the data in your dialog component.
286-
<pre>
287-
<![CDATA[
288-
import { Component, Inject } from '@angular/core';
289-
import { MdcDialogRef, MDC_DIALOG_DATA } from '@angular-mdc/web';
290-
@Component({
291-
// ...
292-
})
293-
export class YourDialog {
294-
constructor(public dialogRef: MdcDialogRef<YourDialog>,
295-
@Inject(MDC_DIALOG_DATA) public data: DialogData) {
296-
userName: string = data.name;
297-
}
298-
}]]>
299-
</pre>
300288

289+
<pre><code highlight code="import { Component, Inject } from '@angular/core';
290+
import {
291+
MdcDialogRef,
292+
MDC_DIALOG_DATA
293+
} from '@angular-mdc/web';
294+
295+
@Component({
296+
// ...
297+
})
298+
export class YourDialog {
299+
constructor(
300+
public dialogRef: MdcDialogRef<YourDialog>,
301+
@Inject(MDC_DIALOG_DATA) data: DialogData) {
302+
userName: string = data.name;
303+
}
304+
}"></code></pre>
301305
<h3 class="demo-content__headline">Configuring dialog content via entryComponents</h3>
302306
<p mdcBody2>Because <code class="docs-markdown-code">MdcDialog</code> instantiates components at run-time, the Angular compiler needs extra information to create the necessary
303307
ComponentFactory for your dialog content component.</p>
304308
<p mdcBody2>For any component loaded into a dialog, you must include your component
305309
class in the list of <code class="docs-markdown-code">entryComponents</code> in your NgModule definition so that the Angular compiler knows to create the ComponentFactory.</p>
306-
<pre>
307-
<![CDATA[
308-
@NgModule({
310+
<pre><code highlight code="@NgModule({
309311
imports: [
310312
// ...
311313
MdcDialogModule
312314
],
313-
314315
declarations: [
315316
AppComponent,
316317
ExampleDialogComponent
317318
],
318-
319319
entryComponents: [
320320
ExampleDialogComponent
321321
],
322-
323-
providers: [],
324322
bootstrap: [AppComponent]
325323
})
326-
export class AppModule {}]]>
327-
</pre>
324+
export class AppModule {}"></code></pre>
328325
</div>

demos/components/slider-demo/slider-demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ <h3 class="demo-content__headline">Continuous Slider - ngModel</h3>
133133
<p>Value from input event: {{continuousInputEventValue}}</p>
134134
<p>Value from change event: {{continuousChangeEventValue}}</p>
135135
</div>
136+
136137
<div class="demo-content">
137138
<h3 class="demo-content__headline">Discrete Slider</h3>
138139
<mdc-slider #demodiscrete [min]="discreteMin" [max]="discreteMax" [discrete]="true" [value]="50"
@@ -149,7 +150,7 @@ <h3 class="demo-content__headline">Discrete Slider</h3>
149150
<div class="demo-content">
150151
<h3 class="demo-content__headline">Discrete Slider with markers</h3>
151152
<mdc-slider #demomarkers [min]="dmMin" [max]="dmMax" [step]="dmStep" ngModel #demoMarkerModel="ngModel"
152-
[discrete]="true" [markers]="true" [value]="20"
153+
discrete markers [value]="20"
153154
(input)="markersInputEventValue = $event.value" (change)="markersChangeEventValue = $event.value"></mdc-slider>
154155
<mdc-text-field [(ngModel)]="dmMin" label="Min" type="number"></mdc-text-field>
155156
<mdc-text-field [(ngModel)]="dmMax" label="Max" type="number"></mdc-text-field>
@@ -164,6 +165,6 @@ <h3 class="demo-content__headline">Discrete Slider with markers</h3>
164165

165166
<div class="demo-content">
166167
<h3 class="demo-content__headline">Custom colors</h3>
167-
<mdc-slider [discrete]="true" [markers]="true" class="demo-slider--custom"></mdc-slider>
168+
<mdc-slider discrete markers class="demo-slider--custom"></mdc-slider>
168169
</div>
169170
</div>

demos/components/textfield-demo/textfield-demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ <h3 class="demo-content__headline">Text Field - FormControl</h3>
245245
<button mdc-button (click)="alternateColors(demoformInput)">Alternate Colors</button>
246246
</div>
247247
<form [formGroup]="demoForm" id="demoForm" (ngSubmit)="submitForm()">
248-
<mdc-text-field #demoformInput formControlName="userName" label="Username" maxlength="10" outlined [helperText]="demoformHelper" required></mdc-text-field>
248+
<mdc-text-field #demoformInput formControlName="userName" label="Username" minlength="3" maxlength="10" outlined [helperText]="demoformHelper" required></mdc-text-field>
249249
<mdc-text-field-helper-text #demoformHelper="mdcHelperText" validation>
250-
<span *ngIf="demoForm.errors?.required">Username is required</span>
250+
<span *ngIf="demoForm.controls['userName'].errors?.required">Username is required</span>
251+
<span *ngIf="demoForm.controls['userName'].errors?.minlength">Username is not long enough</span>
251252
</mdc-text-field-helper-text>
252253
</form>
253254
<div class="demo-layout__row">

demos/components/textfield-demo/textfield-demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class TextFieldDemo {
1818

1919
submitForm() {
2020
if (!this.demoForm.valid) {
21+
this.demoForm.controls['userName'].updateValueAndValidity();
2122
return;
2223
}
2324
}

demos/getting-started/cli-guide.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@ <h2>Step 1: Install Angular CLI</h2>
55
Already have @angular/cli installed? Skip to Step 2.
66

77
<h4>npm</h4>
8-
<pre>npm i -g @angular/cli</pre>
9-
8+
<pre><code highlight lang="bash">npm i -g @angular/cli</code></pre>
109
<h4>yarn</h4>
11-
<pre>yarn global add @angular/cli</pre>
10+
<pre><code highlight lang="bash">yarn global add @angular/cli</code></pre>
1211

1312
<h2>Step 2: Create Project</h2>
14-
If generating a new project, you need to set default CSS preprocessor to scss:
15-
<pre>ng new PROJECT-NAME --style=scss
16-
cd PROJECT-NAME</pre>
13+
If generating a new project, you need to set default CSS preprocessor to SCSS:
14+
<pre><code highlight lang="bash">ng new your-project-name
15+
cd PROJECT-NAME</code></pre>
1716

1817
On existing projects, you need to set default CSS preprocessor to scss:
1918
<pre>ng config schematics.@schematics/angular:component.styleext scss</pre>
2019

2120
<h2>Step 3: Install Angular MDC</h2>
2221
<h4>npm</h4>
23-
<pre>npm i @angular-mdc/web</pre>
22+
<pre><code highlight lang="bash">npm i @angular-mdc/web</code></pre>
2423

2524
<h4>yarn</h4>
26-
<h4><pre>yarn add @angular-mdc/web</pre></h4>
25+
<pre><code highlight lang="bash">yarn add @angular-mdc/web</code></pre>
2726

2827
<h2>Step 4: Import Angular MDC Sass</h2>
2928
Edit src/styles.sass, and insert:
30-
<pre><![CDATA[
29+
<pre><code highlight lang="scss">
3130
$mdc-theme-primary: #1565c0; // primary color
3231
$mdc-theme-secondary: #388e3c; // secondary color
3332

34-
@import "~@angular-mdc/theme/material";]]></pre>
33+
@import "~@angular-mdc/theme/material"
34+
</code></pre>
3535

3636
<h2>Step 5: Import Components</h2>
3737
Now just import the NgModule for each component you want to use.
38-
<pre><![CDATA[import {
38+
<pre><code highlight code="import {
3939
MdcFabModule,
4040
MdcIconModule,
4141
MdcMenuModule
@@ -51,14 +51,14 @@ <h2>Step 5: Import Components</h2>
5151
],
5252
...
5353
})
54-
export class ExampleModule { }]]></pre>
54+
export class ExampleModule { }"></code></pre>
5555

5656
Open app.component.html and add the following markup:
57-
<pre><![CDATA[<button mdc-button [primary]="true" [raised]="true">My Button</button>
57+
<pre><code highlight code="<button mdc-button raised>My Button</button>
5858
5959
<button mdc-fab>
6060
<mdc-icon>edit</mdc-icon>
61-
</button>]]></pre>
61+
</button>"></code></pre>
6262

6363
Run `ng serve` to run your application in develop mode, and navigate to http://localhost:4200
6464
</div>

demos/home/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ <h4 class="demo-landing__label">for Angular</h4>
77
<div class="demo-layout__column demo-layout--center demo-landing__secondary">
88
<p class="demo-landing__subtitle">A faithful and accurate representation of Material Design.</p>
99
<button raised secondary mdc-button [routerLink]="['/getting-started']">Get Started</button>
10-
<span class="demo-landing__version">v0.40.2</span>
10+
<span class="demo-landing__version">v0.41.0-pre.0</span>
1111
</div>

0 commit comments

Comments
 (0)