-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support select
elements
#55
Support select
elements
#55
Conversation
@theinterned this work aims to complement #30. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good!
Before I approve, Can you please add some docs to the readme about select support and call out the gap with multi-selects?
71a2686
to
4d5340d
Compare
select:not([multiple])
elementsselect
elements
@theinterned I've incorporated your suggestion on looping over |
@seanpdoyle there are conflicts since merging #30 — I'll give this a review once those are resolved. Thank you 🙏 |
First, introduce the `PersistableElement` type to incorporate `<input>`, `<textarea>`, and `<select>` elements. Next, incorporate some special handling for `HTMLSelectElement`, since they don't have a `.defaultValue` property. Support for `HTMLSelectElement` instances is generalized for both single and `[multiple]` elements by looping over [HTMLSelectElement.selectedOptions][] while persisting, then setting [HTMLSelectElement.selected][] when restoring. [HTMLSelectElement.selectedOptions]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedOptions [HTMLSelectElement.selected]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement#instance_properties
4d5340d
to
8154f26
Compare
@theinterned I've pushed up a rebased commit. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this 🎉
I'll cut a release
.filter(field => shouldResumeField(field, storageFilter)) | ||
.map(field => { | ||
if (field instanceof HTMLSelectElement) { | ||
return [field.id, Array.from(field.selectedOptions).map(option => option.value)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah cool using selectedOptions
is really nice! I didn't realize it worked equally for multiple and non-multiple selects.
🚀 This has shipped in v0.5.0 |
First, introduce the
PersistableElement
type to incorporate<input>
,<textarea>
, and<select>
elements.Next, incorporate some special handling for
HTMLSelectElement
, sincethey don't have a
.defaultValue
property.Support for
HTMLSelectElement
instances is generalized for bothsingle and
[multiple]
elements by looping overHTMLSelectElement.selectedOptions while persisting, then setting
HTMLSelectElement.selected when restoring.