@@ -122,11 +122,11 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
122
122
123
123
/** Whether the floating label should always float or not. */
124
124
get _shouldAlwaysFloat ( ) {
125
- return this . _floatLabel === 'always' && ! this . _showAlwaysAnimate ;
125
+ return this . floatLabel === 'always' && ! this . _showAlwaysAnimate ;
126
126
}
127
127
128
128
/** Whether the label can float or not. */
129
- get _canLabelFloat ( ) { return this . _floatLabel !== 'never' ; }
129
+ get _canLabelFloat ( ) { return this . floatLabel !== 'never' ; }
130
130
131
131
/** State of the mat-hint and mat-error animations. */
132
132
_subscriptAnimationState : string = '' ;
@@ -148,12 +148,21 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
148
148
* @deprecated Use floatLabel instead.
149
149
*/
150
150
@Input ( )
151
- get floatPlaceholder ( ) { return this . _floatLabel ; }
151
+ get floatPlaceholder ( ) { return this . floatLabel ; }
152
152
set floatPlaceholder ( value : FloatLabelType ) { this . floatLabel = value ; }
153
153
154
- /** Whether the label should always float, never float or float as the user types. */
154
+ /**
155
+ * Whether the label should always float, never float or float as the user types.
156
+ *
157
+ * Note: only the legacy variant supports the `never` option. `never` was originally added as a
158
+ * way to make the floating label emulate the behavior of a standard input placeholder. However
159
+ * the form field now supports both floating labels and placeholders. Therefore in the non-legacy
160
+ * variants the `never` option has been disabled in favor of just using the placeholder.
161
+ */
155
162
@Input ( )
156
- get floatLabel ( ) { return this . _floatLabel ; }
163
+ get floatLabel ( ) {
164
+ return this . variant !== 'legacy' && this . _floatLabel === 'never' ? 'auto' : this . _floatLabel ;
165
+ }
157
166
set floatLabel ( value : FloatLabelType ) {
158
167
if ( value !== this . _floatLabel ) {
159
168
this . _floatLabel = value || this . _labelOptions . float || 'auto' ;
@@ -247,11 +256,14 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
247
256
}
248
257
249
258
_hideControlPlaceholder ( ) {
250
- return ! this . _hasLabel ( ) || ! this . _shouldLabelFloat ( ) ;
259
+ // In the legacy variant the placeholder is promoted to a label if no label is given.
260
+ return this . variant === 'legacy' && ! this . _hasLabel ( ) ||
261
+ this . _hasLabel ( ) && ! this . _shouldLabelFloat ( ) ;
251
262
}
252
263
253
264
_hasFloatingLabel ( ) {
254
- return this . _hasLabel ( ) || this . _hasPlaceholder ( ) ;
265
+ // In the legacy variant the placeholder is promoted to a label if no label is given.
266
+ return this . _hasLabel ( ) || this . variant === 'legacy' && this . _hasPlaceholder ( ) ;
255
267
}
256
268
257
269
/** Determines whether to display hints or errors. */
@@ -264,7 +276,7 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
264
276
_animateAndLockLabel ( ) : void {
265
277
if ( this . _hasFloatingLabel ( ) && this . _canLabelFloat ) {
266
278
this . _showAlwaysAnimate = true ;
267
- this . _floatLabel = 'always' ;
279
+ this . floatLabel = 'always' ;
268
280
269
281
fromEvent ( this . _label . nativeElement , 'transitionend' ) . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
270
282
this . _showAlwaysAnimate = false ;
0 commit comments