Skip to content

fix: select the option bound to the value in setValue on select - #3070

Merged
cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/set-value-select-bound-values
Dec 2, 2026
Merged

cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/set-value-select-bound-values

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

setValue on a <select> compares the value with each option's value string, while v-model compares it with the value bound by :value. So with a v-model select, setValue(null) on <option :value="null"> sets the model to undefined, setValue({ id: 2, name: 'Sith' }) selects the first option bound to an object (#2627), and setValue([1, 3]) on a multiple select bound to numbers selects nothing. Tests work around it with selectedIndex, like this one.

I changed setValue to select the options like vModelSelect does in Vue core, comparing with looseEqual (copied into utils/vueShared.ts, as @vue/shared isn't a dependency). Options still match by their value string too, so string values work as before. I also replaced the docs warning added in #2819.

This is option 2 from this comment. Here's a playground with 2.6.0: https://play.vuejs.org/#eNq1VuuOm0YUfpUjGglQMXQdKZWQcVNV+ydqd6vayR9jaVkYr2cXBsoMeC3H794zF2PAclK1iWRhM+c7t+9cxgfr16ry24ZYoTXjaU0rAZyIpprHjBZVWQs4QFqTRBAEesDIq1jS9MWDmmzgCJu6LMBGfbuHL8qGiU74HqWBIFxMGkFzfgbeNXm+IDlJhUH6wflIxnSG3j8+49kI3D8cwv9ockHvmmKkMDw2KjFLS8YFlI2ASGbl2HXDGGVPvu/b7knMt+UO5S1Ec3DwGUXQsIxsKCMZ/AJ292JDCB8W93c+FzUaoZu907poJmZBAAk0nNRQIYMcxJZAWQlaMoe7kAh4oGjklfCHENpJUWYkx3iSTCMfkdQM2iRvCI9ZwvcshU3DUqmvrP4pjTq/lQWWyRhy4RAzAJ0BWosgK9OmIEz4uqa3OZFvjp3RVuZ6wrYFYruyK6Our8rqkLyH45rgCI37fzek3mtqy9qxtUgb3ZQ1OFpjRT2T9BrKDayQZI309Slf+xhQTQl3XBM+GAUDRL6jU4I+ZWneZAimytFRPoy9jPIqEen2tpUZMrID/ctOtwl7IrYsCkCyS6jo2tpRZzUOQM1UyZ22wLyxEihA4xfEt6JZEPFJVsVQryo0IH5XJ1WFVY/0YGg2z76N2Mfuyc60YbLGrDY4juukNY4P1Za0INjNjg7VcWXL9sKpyx3HWFaa2pU90+xCqBxFscVwCGNr7slFoEOQJ67t9SbWg9VPa1wHeLD2rloS+4qgJXB+mL6b/uz2LB6AZiFM0UJSkBBia0HFNrbgKN30Bxsd3aCjEd6WcBuOPd+mFQs541VOMPyLcG4+Tz+/HWa2uvHg7Vo6HS4HmZ8HU/SsEWvpRz1yIkBguyCF9l+3i4+/L8EZrTiY+u98VD8NMcZgwpu7ccxw6QxHQubkwWByTR+pGZEF60ZBuf4xggc09OYgNY/4C/p7hYoQ3hx0c11bDFrp0/JjR0UIndK1ppZKD92YYYv56hyZkFFhA2ITzgJ9i+D9gS+CFFWOSwTfAGZVTeaHg9q0x+MskK9SoQeyPGt4BXzpWrq8gTSfmnSzy3HuuVxCejvfvlYll92nMV8L2PSUqSN2kPrGDtK1uDY5dyUjs0ALR9AOiWFJJH4NkBiNbpRLYsbX3X+hRg5kN/x6prC9zUx9IBnFmVIjdWXeYoYzcMmyMosL4Tvz3E5wasxawU7W2eDSCF/I3hz7NJMHowWETaeEMhnVev+O8cv/C/+3HVffnKLzwrvSkzeY//3VfuxgU4Qtd+XXYHJ9Lrc1Gdr7AoeankmRVP4zLxkSqBZZbARYvvC02mJrtEelLLa2QlQ8DIKGVS9PfloWwQj2Xq3bAO97EaBkcpb4hBeTR7k/8aZ8RntmeeHHOv4DEDzF8g==

@netlify

netlify Bot commented Dec 1, 2026

Copy link
Copy Markdown

👷 Deploy request for vue-test-utils-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0790164

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vue/test-utils@3070

commit: 0790164

@cexbrayat cexbrayat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@cexbrayat
cexbrayat merged commit a048ea6 into vuejs:main Dec 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants