max-mapper/yo-yo
View on GitHubcontrolled input on select tag requires both select value AND option selected
Open
#37 opened on Jul 10, 2016
help wanted
Repository metrics
- Stars
- (1,322 stars)
- PR merge metrics
- (PR metrics pending)
Description
More of a documentation request than a feature request -- this is how to do a "controlled" (in the React parlance) version of a select tag:
const select = (options, value) =>
yo`<select value="${value}">
${options.map((o) =>
yo`<option value="${o.value}"
${value === o.value ? "selected" : ""}>
${o.label}
</option>`
)}
</select>`
Note that you need to both set a value on the <select> tag and set the selected attribute on the selected <option>.