Skip to content

Commit

Permalink
fix(text-field): label floating after type changes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 469319802
  • Loading branch information
asyncLiz authored and copybara-github committed Aug 22, 2022
1 parent a29ac8b commit 17d92f6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions textfield/lib/text-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,18 @@ export abstract class TextField extends LitElement {
super.willUpdate(changedProperties);
}

protected override updated() {
// If a property such as `type` changes and causes the internal <input>
// value to change without dispatching an event, re-sync it.
const value = this.getInput().value;
if (this.value !== value) {
// Note this is typically inefficient in updated() since it schedules
// another update. However, it is needed for the <input> to fully render
// before checking its value.
this.value = value;
}
}

protected handleInput(event: InputEvent) {
this.dirty = true;
this.value = (event.target as HTMLInputElement).value;
Expand Down

0 comments on commit 17d92f6

Please sign in to comment.