Update value of password field on change event (#22706)

This commit is contained in:
Bram Kragten 2024-11-07 09:53:34 +01:00 committed by GitHub
parent 1e73cebda6
commit 786b9ee8d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -117,8 +117,8 @@ export class HaPasswordField extends LitElement {
.autocapitalize=${this.autocapitalize} .autocapitalize=${this.autocapitalize}
.type=${this._unmaskedPassword ? "text" : "password"} .type=${this._unmaskedPassword ? "text" : "password"}
.suffix=${html`<div style="width: 24px"></div>`} .suffix=${html`<div style="width: 24px"></div>`}
@input=${this._handleInputChange} @input=${this._handleInputEvent}
@change=${this._reDispatchEvent} @change=${this._handleChangeEvent}
></ha-textfield> ></ha-textfield>
<ha-icon-button <ha-icon-button
toggles toggles
@ -153,11 +153,16 @@ export class HaPasswordField extends LitElement {
} }
@eventOptions({ passive: true }) @eventOptions({ passive: true })
private _handleInputChange(ev) { private _handleInputEvent(ev) {
this.value = ev.target.value; this.value = ev.target.value;
} }
@eventOptions({ passive: true }) @eventOptions({ passive: true })
private _handleChangeEvent(ev) {
this.value = ev.target.value;
this._reDispatchEvent(ev);
}
private _reDispatchEvent(oldEvent: Event) { private _reDispatchEvent(oldEvent: Event) {
const newEvent = new Event(oldEvent.type, oldEvent); const newEvent = new Event(oldEvent.type, oldEvent);
this.dispatchEvent(newEvent); this.dispatchEvent(newEvent);