-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix: make <select>
<option value>
behavior consistent
#12316
Conversation
Setting the `value` attribute of an `<option>` element to a falsy value should result in the empty string. This wasn't happening in all situations previously. Fixes #11616
🦋 Changeset detectedLatest commit: 7e55810 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (is_option_element && key === 'value') { | ||
// Because of the "set falsy option values to the empty string" logic below, which can't | ||
// differentiate between a missing value and an explicitly set value of null or undefined, | ||
// we need to remove the attribute here and delete the key from the object. | ||
element.removeAttribute(key); | ||
delete current[key]; | ||
delete next[key]; | ||
} else { | ||
next[key] = null; | ||
} |
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.
It's a shame we need this additional code to be 100% correct. Since it's impossible to remove the value
attribute in the case you set it through a regular (non-spreaded) attribute I'd be totally ok with removing this extra code and adding a comment to the other logic below about a super-edge-case-bug present and the deliberate tradeoff for less code
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.
We decided to remove this logic and live with the super-edge-case (which is also described in the updated comment)
Setting the
value
attribute of an<option>
element to a falsy value should result in the empty string. This wasn't happening in all situations previously. Fixes #11616While this fixes the behavior, I'm also somewhat questioning whether or not this should be the way it works. In other situations a falsy value means removing the attribute. In this case it's not. On the other hand for
value
oninput
elements it's the same behavior and it makes sense there, mostly because the value property is not reflected as an attribute - but for option elements it is. So there are arguments both in favor and against this behavior. Either way, it should be consistent, and this makes it consistent with the Svelte 4 behavior (and fixes the spreading inconsistency that was also present in Svelte 4)Side note: During this I checked what the
value
attribute does for different elements. It's ... really different by element, to say the least:Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint