Accept new value when hitting ENTER to close a prompt dialog#12360
Accept new value when hitting ENTER to close a prompt dialog#12360zsarnett merged 4 commits intohome-assistant:devfrom
Conversation
zsarnett
left a comment
There was a problem hiding this comment.
This will now call the value changed event each time a key is pressed..
Co-authored-by: Zack Barett <zackbarett@hey.com>
Co-authored-by: Zack Barett <zackbarett@hey.com>
steverep
left a comment
There was a problem hiding this comment.
I noticed this issue as well. Someone else reported in #12206. Per my comments, a better fix should be just to get rid of the key up and value changed handler methods, and grab the current field value in the confirm method, saving a bunch of lines of code.
| @@ -77,7 +77,7 @@ class DialogBox extends LitElement { | |||
| dialogInitialFocus | |||
| .value=${this._value || ""} | |||
| @keyup=${this._handleKeyUp} | |||
There was a problem hiding this comment.
This handler is doing nothing because mwc-dialog hits the primary confirm button on enter key down, not up. The bug occurs because the confirm method then gets called before this._value is updated (because the change event only fires when focus is removed).
| .value=${this._value || ""} | ||
| @keyup=${this._handleKeyUp} | ||
| @change=${this._valueChanged} | ||
| @input=${this._valueChanged} |
There was a problem hiding this comment.
This is not a good fix because it's just unnecessarily updating the state variable every time an input character is changed, and probably causing the lit element to keep rescheduling render updates.
…essed
Proposed change
This fixes a bug that causes hitting ENTER to close a prompt dialog to not accept the new value.
Steps to reproduce:
The existing code clearly intends for hitting ENTER (keycode 13) to accept the new value (by calling _confirm) but it doesn't work because the @change event isn't called for keystrokes.
Type of change
Checklist
If user exposed functionality or configuration variables are added/changed: