Skip to content

Commit 4021929

Browse files
crisbetojelbourn
authored andcommitted
docs(select): update live examples to use labels (#15095)
* Fixes a few examples that didn't have labels for the native select. * Switches all of the examples to use the `mat-label`, instead of a `placeholder`. Fixes #15022.
1 parent 8fc97ac commit 4021929

File tree

11 files changed

+29
-13
lines changed

11 files changed

+29
-13
lines changed

src/material-examples/select-disabled/select-disabled-example.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
<h4>mat-select</h4>
66
<mat-form-field>
7-
<mat-select placeholder="Choose an option" [disabled]="disableSelect.value">
7+
<mat-label>Choose an option</mat-label>
8+
<mat-select [disabled]="disableSelect.value">
89
<mat-option value="option1">Option 1</mat-option>
910
<mat-option value="option2" disabled>Option 2 (disabled)</mat-option>
1011
<mat-option value="option3">Option 3</mat-option>
@@ -13,7 +14,8 @@ <h4>mat-select</h4>
1314

1415
<h4>native html select</h4>
1516
<mat-form-field>
16-
<select matNativeControl placeholder="Choose an option" [disabled]="disableSelect.value">
17+
<mat-label>Choose an option</mat-label>
18+
<select matNativeControl [disabled]="disableSelect.value">
1719
<option value="" selected></option>
1820
<option value="volvo">Volvo</option>
1921
<option value="saab" disabled>Saab</option>

src/material-examples/select-error-state-matcher/select-error-state-matcher-example.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h4>mat-select</h4>
22
<mat-form-field>
3-
<mat-select placeholder="Choose one" [formControl]="selected" [errorStateMatcher]="matcher">
3+
<mat-label>Choose one</mat-label>
4+
<mat-select [formControl]="selected" [errorStateMatcher]="matcher">
45
<mat-option>Clear</mat-option>
56
<mat-option value="valid">Valid option</mat-option>
67
<mat-option value="invalid">Invalid option</mat-option>
@@ -14,7 +15,8 @@ <h4>mat-select</h4>
1415

1516
<h4>native html select</h4>
1617
<mat-form-field class="demo-full-width">
17-
<select matNativeControl placeholder="Choose one" [formControl]="nativeSelectFormControl" [errorStateMatcher]="matcher">
18+
<mat-label>Choose one</mat-label>
19+
<select matNativeControl [formControl]="nativeSelectFormControl" [errorStateMatcher]="matcher">
1820
<option value=""></option>
1921
<option value="valid" selected>Valid option</option>
2022
<option value="invalid">Invalid option</option>

src/material-examples/select-form/select-form-example.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<form>
22
<h4>mat-select</h4>
33
<mat-form-field>
4-
<mat-select placeholder="Favorite food" [(ngModel)]="selectedValue" name="food">
4+
<mat-label>Favorite food</mat-label>
5+
<mat-select [(ngModel)]="selectedValue" name="food">
56
<mat-option *ngFor="let food of foods" [value]="food.value">
67
{{food.viewValue}}
78
</mat-option>
@@ -10,7 +11,8 @@ <h4>mat-select</h4>
1011
<p> Selected food: {{selectedValue}} </p>
1112
<h4>native html select</h4>
1213
<mat-form-field>
13-
<select matNativeControl placeholder="Favorite car" [(ngModel)]="selectedCar" name="car">
14+
<mat-label>Favorite car</mat-label>
15+
<select matNativeControl [(ngModel)]="selectedCar" name="car">
1416
<option value="" selected></option>
1517
<option *ngFor="let car of cars" [value]="car.value">
1618
{{car.viewValue}}

src/material-examples/select-hint-error/select-hint-error-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h4>mat select</h4>
22
<mat-form-field>
3-
<mat-select placeholder="Favorite animal" [formControl]="animalControl" required>
3+
<mat-label>Favorite animal</mat-label>
4+
<mat-select [formControl]="animalControl" required>
45
<mat-option>--</mat-option>
56
<mat-option *ngFor="let animal of animals" [value]="animal">
67
{{animal.name}}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<mat-form-field>
2-
<mat-select placeholder="Toppings" [formControl]="toppings" multiple>
2+
<mat-label>Toppings</mat-label>
3+
<mat-select [formControl]="toppings" multiple>
34
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
45
</mat-select>
56
</mat-form-field>

src/material-examples/select-no-ripple/select-no-ripple-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<mat-form-field>
2-
<mat-select placeholder="Select an option" disableRipple>
2+
<mat-label>Select an option</mat-label>
3+
<mat-select disableRipple>
34
<mat-option value="1">Option 1</mat-option>
45
<mat-option value="2">Option 2</mat-option>
56
<mat-option value="3">Option 3</mat-option>

src/material-examples/select-optgroup/select-optgroup-example.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h4>mat-select</h4>
22
<mat-form-field>
3-
<mat-select placeholder="Pokemon" [formControl]="pokemonControl">
3+
<mat-label>Pokemon</mat-label>
4+
<mat-select [formControl]="pokemonControl">
45
<mat-option>-- None --</mat-option>
56
<mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
67
[disabled]="group.disabled">
@@ -13,6 +14,7 @@ <h4>mat-select</h4>
1314

1415
<h4>native html select</h4>
1516
<mat-form-field>
17+
<mat-label>Cars</mat-label>
1618
<select matNativeControl>
1719
<optgroup label="Swedish Cars">
1820
<option value="volvo">volvo</option>

src/material-examples/select-overview/select-overview-example.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h4>Basic mat-select</h4>
22
<mat-form-field>
3-
<mat-select placeholder="Favorite food">
3+
<mat-label>Favorite food</mat-label>
4+
<mat-select>
45
<mat-option *ngFor="let food of foods" [value]="food.value">
56
{{food.viewValue}}
67
</mat-option>
@@ -9,6 +10,7 @@ <h4>Basic mat-select</h4>
910

1011
<h4>Basic native select</h4>
1112
<mat-form-field>
13+
<mat-label>Cars</mat-label>
1214
<select matNativeControl required>
1315
<option value="volvo">Volvo</option>
1416
<option value="saab">Saab</option>

src/material-examples/select-panel-class/select-panel-class-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<mat-form-field>
2-
<mat-select placeholder="Panel color" [formControl]="panelColor"
2+
<mat-label>Panel color</mat-label>
3+
<mat-select [formControl]="panelColor"
34
panelClass="example-panel-{{panelColor.value}}">
45
<mat-option value="red">Red</mat-option>
56
<mat-option value="green">Green</mat-option>

src/material-examples/select-reset/select-reset-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h4>mat-select</h4>
22
<mat-form-field>
3-
<mat-select placeholder="State">
3+
<mat-label>State</mat-label>
4+
<mat-select>
45
<mat-option>None</mat-option>
56
<mat-option *ngFor="let state of states" [value]="state">{{state}}</mat-option>
67
</mat-select>

src/material-examples/select-value-binding/select-value-binding-example.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<mat-form-field>
2+
<mat-label>Select an option</mat-label>
23
<mat-select [(value)]="selected">
34
<mat-option>None</mat-option>
45
<mat-option value="option1">Option 1</mat-option>

0 commit comments

Comments
 (0)