Skip to content

Commit

Permalink
feat(listbox): support form reset
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Oct 10, 2024
1 parent 7f03c31 commit 2de1313
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ export default CustomElement
// Unbind and release
_listbox.removeEventListener('change', this._onListboxChangeListener);
_listbox.removeEventListener('click', this._onListboxClickListener);
_listbox._handleFormReset = true;
}
this._listbox = listbox;
if (listbox) {
Expand All @@ -620,6 +621,7 @@ export default CustomElement
listbox.required = true; // Don't allow unclick
}

_listbox._handleFormReset = false;
listbox.addEventListener('change', this._onListboxChangeListener);
listbox.addEventListener('click', this._onListboxChangeListener);
this.populateInputFromListbox();
Expand Down
5 changes: 4 additions & 1 deletion components/Listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default List
/** @type {HTMLCollectionOf<InstanceType<ListOption>>} */
_selectedOptionsCollection: null,
_handlingSelectedness: false,
_handleFormReset: true,
})
.define({
options() {
Expand Down Expand Up @@ -103,7 +104,9 @@ export default List
this.updateAriaProperty('ariaMultiSelectable', newValue ? 'true' : 'false');
},
_formResetChanged(oldValue, newValue) {
// TODO: Unset dirty
if (!newValue) return;
if (!this._handleFormReset) return;
this.value = this.defaultValue;
},
connected() {
if (!this.hasAttribute('tabindex')) {
Expand Down

0 comments on commit 2de1313

Please sign in to comment.