Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ba089e9

Browse files
refactor(textfield): Unwrap submethod calls
1 parent 15598e8 commit ba089e9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/mdc-textfield/foundation.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,28 @@ class MDCTextfieldFoundation extends MDCFoundation {
191191
}
192192

193193
/**
194+
* Changes the floating label's state
194195
* @private
195196
*/
196-
forceLayout_() {
197-
// Don't do anything if the input is still focused.
197+
updateLabelFloat_() {
198+
// Don't do anything if the input is focused.
198199
if (!this.isFocused_) {
199-
this.activateFocus_();
200-
this.deactivateFocus_();
200+
const {LABEL_FLOAT_ABOVE, LABEL_SHAKE} = MDCTextfieldFoundation.cssClasses;
201+
const input = this.getNativeInput_();
202+
203+
this.adapter_.removeClassFromLabel(LABEL_SHAKE);
204+
this.showHelptext_();
205+
206+
if (input.value) {
207+
this.adapter_.addClassToLabel(LABEL_FLOAT_ABOVE);
208+
}
209+
else{
210+
this.adapter_.removeClassFromLabel(LABEL_FLOAT_ABOVE);
211+
}
212+
213+
if (!this.useCustomValidityChecking_) {
214+
this.changeValidity_(input.checkValidity());
215+
}
201216
}
202217
}
203218

@@ -366,7 +381,7 @@ class MDCTextfieldFoundation extends MDCFoundation {
366381
get: desc.get,
367382
set: (value) => {
368383
desc.set.call(nativeInputElement, value);
369-
this.forceLayout_();
384+
this.updateLabelFloat_();
370385
},
371386
configurable: desc.configurable,
372387
enumerable: desc.enumerable,

0 commit comments

Comments
 (0)