Skip to content

Commit 684ea65

Browse files
Splaktarjelbourn
authored andcommitted
docs(form-field): examples should use fill appearance by default (#18222)
- stop using the soon to be deprecated legacy appearance by default Fixes #14792 (cherry picked from commit 3168e94)
1 parent 8ea430f commit 684ea65

15 files changed

+84
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<mat-form-field>
2-
<example-tel-input placeholder="Phone number" required></example-tel-input>
1+
<mat-form-field appearance="fill">
2+
<mat-label>Phone number</mat-label>
3+
<example-tel-input required></example-tel-input>
34
<mat-icon matSuffix>phone</mat-icon>
45
<mat-hint>Include area code</mat-hint>
56
</mat-form-field>
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.example-container {
2-
display: flex;
3-
flex-direction: column;
4-
}
5-
6-
.example-container > * {
7-
width: 100%;
1+
.example-container .mat-form-field + .mat-form-field {
2+
margin-left: 8px;
83
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="example-container">
2-
<mat-form-field>
3-
<input matInput placeholder="Enter your email" [formControl]="email" required>
2+
<mat-form-field appearance="fill">
3+
<mat-label>Enter your email</mat-label>
4+
<input matInput placeholder="[email protected]" [formControl]="email" required>
45
<mat-error *ngIf="email.invalid">{{getErrorMessage()}}</mat-error>
56
</mat-form-field>
67
</div>
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.example-container {
2-
display: flex;
3-
flex-direction: column;
4-
}
5-
6-
.example-container > * {
7-
width: 100%;
1+
.example-container .mat-form-field + .mat-form-field {
2+
margin-left: 8px;
83
}

src/components-examples/material/form-field/form-field-hint/form-field-hint-example.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<div class="example-container">
2-
<mat-form-field hintLabel="Max 10 characters">
3-
<input matInput #input maxlength="10" placeholder="Enter some input">
2+
<mat-form-field hintLabel="Max 10 characters" appearance="fill">
3+
<mat-label>Enter some input</mat-label>
4+
<input matInput #input maxlength="10" placeholder="Ex. Nougat">
45
<mat-hint align="end">{{input.value?.length || 0}}/10</mat-hint>
56
</mat-form-field>
67

7-
<mat-form-field>
8-
<mat-select placeholder="Select me">
8+
<mat-form-field appearance="fill">
9+
<mat-label>Select me</mat-label>
10+
<mat-select>
911
<mat-option value="option">Option</mat-option>
1012
</mat-select>
1113
<mat-hint align="end">Here's the dropdown arrow ^</mat-hint>

src/components-examples/material/form-field/form-field-label/form-field-label-example.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
.example-container {
2-
display: flex;
3-
flex-direction: column;
1+
.example-container .mat-form-field + .mat-form-field {
2+
margin-left: 8px;
43
}
54

6-
.example-container > * {
7-
width: 100%;
5+
.example-container .mat-form-field {
6+
width: 220px;
87
}
98

109
.example-container form {
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
<div class="example-container">
2-
<form class="example-container" [formGroup]="options">
3-
<mat-checkbox formControlName="hideRequired">Hide required marker</mat-checkbox>
2+
<form [formGroup]="options">
3+
<mat-checkbox [formControl]="hideRequiredControl">Hide required marker</mat-checkbox>
44
<div>
55
<label>Float label: </label>
6-
<mat-radio-group formControlName="floatLabel">
6+
<mat-radio-group [formControl]="floatLabelControl">
77
<mat-radio-button value="auto">Auto</mat-radio-button>
88
<mat-radio-button value="always">Always</mat-radio-button>
9-
<mat-radio-button value="never">Never</mat-radio-button>
109
</mat-radio-group>
1110
</div>
12-
</form>
1311

14-
<mat-form-field
15-
[hideRequiredMarker]="options.value.hideRequired"
16-
[floatLabel]="options.value.floatLabel">
17-
<input matInput placeholder="Simple placeholder" required>
18-
</mat-form-field>
12+
<mat-form-field appearance="fill"
13+
[hideRequiredMarker]="hideRequiredControl.value"
14+
[floatLabel]="floatLabelControl.value">
15+
<input matInput placeholder="Simple placeholder" required>
16+
</mat-form-field>
1917

20-
<mat-form-field [floatLabel]="options.value.floatLabel">
21-
<mat-label>Both a label and a placeholder</mat-label>
22-
<input matInput placeholder="Simple placeholder">
23-
</mat-form-field>
18+
<mat-form-field appearance="fill" [floatLabel]="floatLabelControl.value">
19+
<mat-label>Both a label and a placeholder</mat-label>
20+
<input matInput placeholder="Simple placeholder">
21+
</mat-form-field>
2422

25-
<mat-form-field
26-
[hideRequiredMarker]="options.value.hideRequired"
27-
[floatLabel]="options.value.floatLabel">
28-
<mat-select required>
29-
<mat-option>-- None --</mat-option>
30-
<mat-option value="option">Option</mat-option>
31-
</mat-select>
32-
<mat-label><mat-icon>favorite</mat-icon> <b> Fancy</b> <i> label</i></mat-label>
33-
</mat-form-field>
23+
<mat-form-field appearance="fill"
24+
[hideRequiredMarker]="hideRequiredControl.value"
25+
[floatLabel]="floatLabelControl.value">
26+
<mat-select required>
27+
<mat-option>-- None --</mat-option>
28+
<mat-option value="option">Option</mat-option>
29+
</mat-select>
30+
<mat-label><mat-icon>favorite</mat-icon> <b> Fancy</b> <i> label</i></mat-label>
31+
</mat-form-field>
32+
</form>
3433
</div>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {FormBuilder, FormGroup} from '@angular/forms';
2+
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
33

44
/** @title Form field with label */
55
@Component({
@@ -9,11 +9,13 @@ import {FormBuilder, FormGroup} from '@angular/forms';
99
})
1010
export class FormFieldLabelExample {
1111
options: FormGroup;
12+
hideRequiredControl = new FormControl(false);
13+
floatLabelControl = new FormControl('auto');
1214

1315
constructor(fb: FormBuilder) {
1416
this.options = fb.group({
15-
hideRequired: false,
16-
floatLabel: 'auto',
17+
hideRequired: this.hideRequiredControl,
18+
floatLabel: this.floatLabelControl,
1719
});
1820
}
1921
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
.example-container {
2-
display: flex;
3-
flex-direction: column;
4-
}
5-
6-
.example-container > * {
7-
width: 100%;
8-
}
1+
/** No CSS for this example */
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<div class="example-container">
2-
<mat-form-field>
3-
<input matInput placeholder="Input">
2+
<mat-form-field appearance="fill">
3+
<mat-label>Input</mat-label>
4+
<input matInput>
45
</mat-form-field>
5-
6-
<mat-form-field>
7-
<textarea matInput placeholder="Textarea"></textarea>
8-
</mat-form-field>
9-
10-
<mat-form-field>
11-
<mat-select placeholder="Select">
6+
<br>
7+
<mat-form-field appearance="fill">
8+
<mat-label>Select</mat-label>
9+
<mat-select>
1210
<mat-option value="option">Option</mat-option>
1311
</mat-select>
1412
</mat-form-field>
13+
<br>
14+
<mat-form-field appearance="fill">
15+
<mat-label>Textarea</mat-label>
16+
<textarea matInput></textarea>
17+
</mat-form-field>
1518
</div>

0 commit comments

Comments
 (0)