@@ -4,14 +4,14 @@ <h1>Select Menus</h1>
4
4
MDC Select provides Material Design single-option select menus.
5
5
< h2 > References</ h2 >
6
6
< ul >
7
- < li > < a mdc-button href ="https://material.io/guidelines/components/text-fields.html "
8
- target =" _blank " rel =" noopener noreferrer " > Material Design guidelines: Text Fields</ a >
7
+ < li > < a mdc-button href ="https://material.io/guidelines/components/text-fields.html " target =" _blank " rel =" noopener noreferrer " > Material
8
+ Design guidelines: Text Fields</ a >
9
9
</ li >
10
- < li > < a mdc-button href ="https://material.io/guidelines/components/menus.html "
11
- target =" _blank " rel =" noopener noreferrer " > Material Design guidelines: Menus</ a >
10
+ < li > < a mdc-button href ="https://material.io/guidelines/components/menus.html " target =" _blank " rel =" noopener noreferrer " > Material
11
+ Design guidelines: Menus</ a >
12
12
</ li >
13
13
< li > < a mdc-button href ="https://github.com/material-components/material-components-web/blob/master/packages/mdc-select/README.md "
14
- target ="_blank " rel ="noopener noreferrer "> Material Components Web</ a >
14
+ target ="_blank " rel ="noopener noreferrer "> Material Components Web</ a >
15
15
</ li >
16
16
</ ul >
17
17
< h2 > Import</ h2 >
@@ -117,10 +117,33 @@ <h2>Design & API Documentation</h2>
117
117
</ tr >
118
118
</ tbody >
119
119
</ table >
120
+
121
+ < p >
122
+ < span class ="docs-api-class-selector-label "> Selector:</ span >
123
+ < span class ="docs-api-class-selector-name "> mdc-helper-text</ span >
124
+ </ p >
125
+ < table >
126
+ < thead >
127
+ < tr >
128
+ < th > Properties</ th >
129
+ < th > Description</ th >
130
+ </ tr >
131
+ </ thead >
132
+ < tbody >
133
+ < tr >
134
+ < td > validation: boolean</ td >
135
+ < td > Help text can be used to provide additional validation messages.</ td >
136
+ </ tr >
137
+ < tr >
138
+ < td > persistent: boolean</ td >
139
+ < td > Help text will always be visible.</ td >
140
+ </ tr >
141
+ </ tbody >
142
+ </ table >
120
143
</ div >
121
144
< h2 > Basic Usage</ h2 >
122
- < a mdc-button href ="https://stackblitz.com/edit/angular-mdc-select "
123
- target =" _blank " rel =" noopener noreferrer " > EDIT IN STACKBLITZ</ a >
145
+ < a mdc-button href ="https://stackblitz.com/edit/angular-mdc-select " target =" _blank " rel =" noopener noreferrer " > EDIT
146
+ IN STACKBLITZ</ a >
124
147
</ div >
125
148
126
149
< div class ="demo-content ">
@@ -129,17 +152,19 @@ <h3 class="demo-content__headline">Select</h3>
129
152
< button mdc-button (click) ="native1.outlined = !native1.outlined "> Outlined: {{native1.outlined ? 'On' : 'Off'}}</ button >
130
153
< button mdc-button (click) ="native1.required = !native1.required "> Required: {{native1.required ? 'On' : 'Off'}}</ button >
131
154
< button mdc-button (click) ="native1.disabled = !native1.disabled "> Disabled: {{native1.disabled ? 'On' : 'Off'}}</ button >
132
- < button mdc-button (click) ="native1.floatLabel = !native1.floatLabel "> Float Label: {{native1.floatLabel ? 'On' : 'Off'}}</ button >
133
- < button mdc-button (click) ="native1.setSelectedIndex(2) "> Set Index (2)</ button >
155
+ < button mdc-button (click) ="native1.floatLabel = !native1.floatLabel "> Float Label: {{native1.floatLabel ? 'On' :
156
+ 'Off'}}</ button >
157
+ < button mdc-button (click) ="native1.autosize = !native1.autosize "> Autosize: {{native1.autosize ? 'On' : 'Off'}}</ button >
158
+ < button mdc-button (click) ="native1.setSelectedIndex(2) "> Set Index (2)</ button >
134
159
</ div >
135
160
< mdc-form-field >
136
- < mdc-select #native1 required placeholder ="Select Meal " autosize [helperText] =" fruitHelper " >
161
+ < mdc-select #native1 required placeholder ="Select Meal " autosize >
137
162
< mdc-icon mdcSelectIcon > fastfood</ mdc-icon >
138
163
< option *ngFor ="let food of foods " [value] ="food.value " [disabled] ="food.disabled ">
139
164
{{food.viewValue}}
140
165
</ option >
141
166
</ mdc-select >
142
- < p mdcSelectHelperText #fruitHelper =" mdcSelectHelperText " validation >
167
+ < p mdcHelperText validation >
143
168
< span *ngIf ="!native1.value "> Meal selection is required</ span >
144
169
</ p >
145
170
</ mdc-form-field >
@@ -148,13 +173,13 @@ <h3 class="demo-content__headline">Select</h3>
148
173
< div class ="demo-content ">
149
174
< h3 class ="demo-content__headline "> Select examples</ h3 >
150
175
< mdc-form-field >
151
- < mdc-select >
176
+ < mdc-select #example1 >
152
177
< option value ="apple "> Apple</ option >
153
178
< option value ="orange "> Orange</ option >
154
179
</ mdc-select >
155
180
</ mdc-form-field >
156
181
< mdc-form-field >
157
- < mdc-select placeholder ="Unit " outlined >
182
+ < mdc-select placeholder ="Unit ">
158
183
< option value ="kg "> kg</ option >
159
184
< option value ="ml "> ml</ option >
160
185
</ mdc-select >
@@ -179,14 +204,15 @@ <h3 class="demo-content__headline">Select with ngModel</h3>
179
204
< button mdc-button (click) ="select.outlined = !select.outlined "> Outlined: {{select.outlined ? 'On' : 'Off'}}</ button >
180
205
< button mdc-button (click) ="select.required = !select.required "> Required: {{select.required ? 'On' : 'Off'}}</ button >
181
206
< button mdc-button (click) ="select.disabled = !select.disabled "> Disabled: {{select.disabled ? 'On' : 'Off'}}</ button >
182
- < button mdc-button (click) ="select.floatLabel = !select.floatLabel "> Float Label: {{select.floatLabel ? 'On' : 'Off'}}</ button >
207
+ < button mdc-button (click) ="select.floatLabel = !select.floatLabel "> Float Label: {{select.floatLabel ? 'On' :
208
+ 'Off'}}</ button >
183
209
< button mdc-button (click) ="demoSelectModel.reset() "> Clear Selection</ button >
184
210
< button mdc-button (click) ="select.setSelectionByValue('fruit-3') "> Select Fruit</ button >
185
211
< button mdc-button (click) ="select.setSelectedIndex(4) "> Set Index (4)</ button >
186
212
</ div >
187
213
< form #demoSelectForm ="ngForm " id ="demoSelectForm ">
188
- < mdc-select #select placeholder ="Favorite food " ngModel #demoSelectModel ="ngModel " name ="food " outlined
189
- (change) =" onChange($event) " (selectionChange) ="onSelectionChange($event) ">
214
+ < mdc-select #select placeholder ="Favorite food " ngModel #demoSelectModel ="ngModel " name ="food " outlined (change) =" onChange($event) "
215
+ (selectionChange) ="onSelectionChange($event) ">
190
216
< option *ngFor ="let food of foods " [value] ="food.value " [disabled] ="food.disabled ">
191
217
{{food.viewValue}}
192
218
</ option >
@@ -201,22 +227,53 @@ <h3 class="demo-content__headline">Select with ngModel</h3>
201
227
< div class ="demo-content ">
202
228
< h3 class ="demo-content__headline "> Select with FormControl</ h3 >
203
229
< div class ="demo-layout__row ">
204
- < button mdc-button (click) ="select2.outlined = !select2.outlined "> Outlined: {{select2.outlined ? 'On' : 'Off'}}</ button >
205
- < button mdc-button (click) ="select2.required = !select2.required "> Required: {{select2.required ? 'On' : 'Off'}}</ button >
206
- < button mdc-button (click) ="select2.disabled = !select2.disabled "> Disabled: {{select2.disabled ? 'On' : 'Off'}}</ button >
207
- < button mdc-button (click) ="select2.floatLabel = !select2.floatLabel "> Float Label: {{select2.floatLabel ? 'On' : 'Off'}}</ button >
208
- < button mdc-button (click) ="foodControl.reset() "> Reset Selection</ button >
209
- < button mdc-button (click) ="select2.setSelectionByValue('pizza-1') "> Select Pizza</ button >
210
- < button mdc-button (click) ="foodControl.setValue('pizza-1') "> Set Form Value</ button >
211
- < button mdc-button (click) ="select2.setSelectedIndex(1) "> Set Index (1)</ button >
230
+ < button mdc-button (click) ="favoriteFood.outlined = !favoriteFood.outlined "> Outlined: {{favoriteFood.outlined ?
231
+ 'On' : 'Off'}}</ button >
232
+ < button mdc-button (click) ="favoriteFood.required = !favoriteFood.required "> Required: {{favoriteFood.required ?
233
+ 'On' : 'Off'}}</ button >
234
+ < button mdc-button (click) ="favoriteFood.disabled = !favoriteFood.disabled "> Disabled: {{favoriteFood.disabled ?
235
+ 'On' : 'Off'}}</ button >
236
+ < button mdc-button (click) ="favoriteFood.floatLabel = !favoriteFood.floatLabel "> Float Label:
237
+ {{favoriteFood.floatLabel ? 'On' : 'Off'}}</ button >
238
+ < button mdc-button (click) ="favoriteFood.reset() "> Reset Selection</ button >
239
+ < button mdc-button (click) ="favoriteFood.setSelectionByValue('pizza-1') "> Select Pizza</ button >
240
+ < button mdc-button (click) ="favoriteFood.setValue('pizza-1') "> Set Form Value</ button >
241
+ < button mdc-button (click) ="favoriteFood.setSelectedIndex(1) "> Set Index (1)</ button >
212
242
</ div >
213
- < mdc-select #select2 placeholder ="Favorite food " [formControl] ="foodControl ">
214
- < option *ngFor ="let food of foods " [value] ="food.value " [disabled] ="food.disabled ">
215
- {{food.viewValue}}
216
- </ option >
217
- </ mdc-select >
218
- < p > Value: {{ foodControl.value }}</ p >
219
- < p > Touched: {{ foodControl.touched }}</ p >
220
- < p > Dirty: {{ foodControl.dirty }}</ p >
243
+ < form [formGroup] ="foodForm " id ="foodForm " (ngSubmit) ="submitForm() " #formDirective ="ngForm ">
244
+ < mdc-form-field >
245
+ < mdc-select #favoriteFood placeholder ="Favorite food " formControlName ="favoriteFood ">
246
+ < option *ngFor ="let food of foods " [value] ="food.value " [disabled] ="food.disabled ">
247
+ {{food.viewValue}}
248
+ </ option >
249
+ </ mdc-select >
250
+ < mdc-helper-text mdcHelperText validation >
251
+ < span *ngIf ="foodForm.controls['favoriteFood'].hasError('required') "> Username is required</ span >
252
+ </ mdc-helper-text >
253
+ </ mdc-form-field >
254
+ < div class ="demo-layout__row ">
255
+ < button mdc-button type ="submit "> Submit</ button >
256
+ < button mdc-button type ="button " (click) ="resetForm(formDirective) "> Reset</ button >
257
+ </ div >
258
+ </ form >
259
+ < p > Control Valid: {{foodForm.controls['favoriteFood'].valid}}</ p >
260
+ < p > Dirty: {{ foodForm.dirty }}</ p >
261
+ < p > Valid: {{ foodForm.valid }}</ p >
262
+ < p > Pristine: {{ foodForm.pristine }}</ p >
263
+ < p > Touched: {{ foodForm.touched }}</ p >
264
+ < p > Value: {{ foodForm.value | json }}</ p >
265
+ </ div >
266
+
267
+ < div class ="demo-content ">
268
+ < h3 class ="demo-content__headline "> Enhanced Select</ h3 >
269
+ < mdc-form-field >
270
+ < mdc-select placeholder ="Fruit ">
271
+ < mdc-list >
272
+ < mdc-list-item > Apple</ mdc-list-item >
273
+ < mdc-list-item > Orange</ mdc-list-item >
274
+ < mdc-list-item > Banana</ mdc-list-item >
275
+ </ mdc-list >
276
+ </ mdc-select >
277
+ </ mdc-form-field >
221
278
</ div >
222
- </ div >
279
+ </ div >
0 commit comments