-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
<select>
and <option>
elements are getting incorrect/inconsistent value
attribute when the value is nullish when using dynamic assignment of the value attribute or when using object spread.
It seems to be due to how nullish values are applied to the <option>
element. I'm running into the following scenario's:
<option value={undefined}>
renders with an emptyvalue
attribute.<option {value}>
with a non-reactive variable renders with an emptyvalue
attribute.<option {value}>
with a reactive variable renders without avalue
attribute.<option {...value}>
or<option {...{value}}>
with a non-reactive variable renders withoutvalue
attribute.<option {...value}>
or<option {...{value}}>
with a reactive variable renders withoutvalue
attribute.
Which makes it impossible to set the value of an <option>
to undefined
or null
in specific scenarios, since the value
prop of an HTMLOptionElement
fallback to the label when no value
attribute is provided.
This is causing troubles when using <select bind:value>
with a default value (nullish), on initial mount the value will be nullish, once mounted the value is updated to the label of whatever the associated <option>
has.
I have not tested this, but I would assume similar scenarios might apply to checkbox and radio inputs.
Reproduction
Logs
No response
System Info
System:
OS: macOS 14.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 370.41 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
pnpm: 8.15.6 - ~/.nvm/versions/node/v20.11.1/bin/pnpm
bun: 1.1.4 - ~/.bun/bin/bun
Browsers:
Chrome: 124.0.6367.202
Edge: 124.0.2478.97
Safari: 17.4.1
Severity
annoyance