Skip to content

Commit a9013a5

Browse files
committed
remove the floatLabel=never option in the new variants
1 parent a44276a commit a9013a5

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/lib/form-field/form-field.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
122122

123123
/** Whether the floating label should always float or not. */
124124
get _shouldAlwaysFloat() {
125-
return this._floatLabel === 'always' && !this._showAlwaysAnimate;
125+
return this.floatLabel === 'always' && !this._showAlwaysAnimate;
126126
}
127127

128128
/** Whether the label can float or not. */
129-
get _canLabelFloat() { return this._floatLabel !== 'never'; }
129+
get _canLabelFloat() { return this.floatLabel !== 'never'; }
130130

131131
/** State of the mat-hint and mat-error animations. */
132132
_subscriptAnimationState: string = '';
@@ -148,12 +148,21 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
148148
* @deprecated Use floatLabel instead.
149149
*/
150150
@Input()
151-
get floatPlaceholder() { return this._floatLabel; }
151+
get floatPlaceholder() { return this.floatLabel; }
152152
set floatPlaceholder(value: FloatLabelType) { this.floatLabel = value; }
153153

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+
*/
155162
@Input()
156-
get floatLabel() { return this._floatLabel; }
163+
get floatLabel() {
164+
return this.variant !== 'legacy' && this._floatLabel === 'never' ? 'auto' : this._floatLabel;
165+
}
157166
set floatLabel(value: FloatLabelType) {
158167
if (value !== this._floatLabel) {
159168
this._floatLabel = value || this._labelOptions.float || 'auto';
@@ -247,11 +256,14 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
247256
}
248257

249258
_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();
251262
}
252263

253264
_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();
255267
}
256268

257269
/** Determines whether to display hints or errors. */
@@ -264,7 +276,7 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
264276
_animateAndLockLabel(): void {
265277
if (this._hasFloatingLabel() && this._canLabelFloat) {
266278
this._showAlwaysAnimate = true;
267-
this._floatLabel = 'always';
279+
this.floatLabel = 'always';
268280

269281
fromEvent(this._label.nativeElement, 'transitionend').pipe(take(1)).subscribe(() => {
270282
this._showAlwaysAnimate = false;

0 commit comments

Comments
 (0)