Skip to content

Commit 17d92f6

Browse files
asyncLizcopybara-github
authored andcommitted
fix(text-field): label floating after type changes
PiperOrigin-RevId: 469319802
1 parent a29ac8b commit 17d92f6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

textfield/lib/text-field.ts

+12
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,18 @@ export abstract class TextField extends LitElement {
506506
super.willUpdate(changedProperties);
507507
}
508508

509+
protected override updated() {
510+
// If a property such as `type` changes and causes the internal <input>
511+
// value to change without dispatching an event, re-sync it.
512+
const value = this.getInput().value;
513+
if (this.value !== value) {
514+
// Note this is typically inefficient in updated() since it schedules
515+
// another update. However, it is needed for the <input> to fully render
516+
// before checking its value.
517+
this.value = value;
518+
}
519+
}
520+
509521
protected handleInput(event: InputEvent) {
510522
this.dirty = true;
511523
this.value = (event.target as HTMLInputElement).value;

0 commit comments

Comments
 (0)