Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit abfd276

Browse files
authored
fix(textfield): Throws exception with Ivy (#2114)
closes #2113
1 parent cdf889c commit abfd276

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

packages/textfield/text-field.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
192192
set outlined(value: boolean) {
193193
const newValue = coerceBooleanProperty(value);
194194
this._outlined = newValue;
195-
this._layout();
195+
if (this._initialized) {
196+
this._layout();
197+
}
196198
}
197199
private _outlined = false;
198200

@@ -453,15 +455,17 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
453455
this._setDefaultGlobalOptions();
454456
}
455457

458+
async _asyncBuildFoundation(): Promise<void> {
459+
this._foundation = this.getDefaultFoundation();
460+
}
461+
456462
ngAfterViewInit(): void {
457-
this._asyncBuildFoundation()
458-
.then(() => {
459-
this.init();
460-
});
463+
this.init();
461464
}
462465

463466
ngOnDestroy(): void {
464467
this.destroy();
468+
this._foundation.destroy();
465469
}
466470

467471
ngDoCheck(): void {
@@ -473,18 +477,12 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
473477
}
474478
}
475479

476-
async _asyncBuildFoundation(): Promise<void> {
477-
this._foundation = this.getDefaultFoundation();
478-
}
479-
480-
async _asyncInitFoundation(): Promise<void> {
481-
this._foundation.init();
482-
}
483-
484480
init(): void {
485-
this._asyncInitFoundation()
481+
this._initialized = true;
482+
483+
this._asyncBuildFoundation()
486484
.then(() => {
487-
this._initialized = true;
485+
this._foundation.init();
488486

489487
if (!this.fullwidth && !this.outlined && !this.textarea) {
490488
this._ripple = new MdcRipple(this.elementRef);
@@ -599,14 +597,13 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
599597
}
600598

601599
focus(): void {
602-
if (!this.disabled) {
603-
this._getInputElement().focus();
604-
}
600+
this._getInputElement()?.focus();
605601
}
606602

607603
/** Initializes Text Field's internal state based on the environment state */
608604
private _layout(): void {
609605
this.destroy();
606+
610607
this.init();
611608
this._changeDetectorRef.markForCheck();
612609

@@ -657,9 +654,10 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
657654

658655
/** Override MdcTextFieldBase destroy method */
659656
destroy(): void {
657+
this._initialized = false;
658+
660659
this._lineRipple?.destroy();
661660
this._ripple?.destroy();
662-
this._foundation?.destroy();
663661
}
664662

665663
private _isValid(): boolean {

0 commit comments

Comments
 (0)