Skip to content

fix(Select): move selected from <option> to defaultValue on <select> - #2511

Merged
joshblack merged 3 commits into
mainfrom
fix/update-select-placeholder
Nov 2, 2022
Merged

fix(Select): move selected from <option> to defaultValue on <select>#2511
joshblack merged 3 commits into
mainfrom
fix/update-select-placeholder

Conversation

@joshblack

Copy link
Copy Markdown
Member

We currently set selected on the <option> within a <select> when placeholder is provided. When doing so, we receive the following error from styled-components:

Warning: Use the `defaultValue` or `value` props on <select> instead of setting `selected` on <option>.
at option
at select
at StyledComponent (/Users/joshblack/gh/primer/react/node_modules/styled-components/dist/styled-components.cjs.js:1950:5)
at Select__StyledSelect
at span
at StyledComponent (/Users/joshblack/gh/primer/react/node_modules/styled-components/dist/styled-components.cjs.js:1950:5)
at _TextInputWrapper__TextInputWrapper
at block (/Users/joshblack/gh/primer/react/src/Select.tsx:67:5)

This PR removes the selected prop from <option> and instead optionally specifies the defaultValue if placeholder is present.

Note
When a consumer passes in defaultValue, it should continue to override whatever is provided since {...rest} is applied afterdefaultValue

@joshblack
joshblack requested review from a team and josepmartinsNovember 1, 2022 18:26
@changeset-bot

changeset-botBot commented Nov 1, 2022

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aeac346

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/reactPatch

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

@github-actions

github-actionsBot commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js78.82 KB (+0.01% 🔺)
dist/browser.umd.js79.47 KB (+0.01% 🔺)

@joshblack
joshblack temporarily deployed to github-pages November 1, 2022 18:33 Inactive
@josepmartins
josepmartins temporarily deployed to github-pages November 2, 2022 09:40 Inactive

@josepmartinsjosepmartins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@joshblack
joshblack merged commit 0a94420 into mainNov 2, 2022
@joshblack
joshblack deleted the fix/update-select-placeholder branch November 2, 2022 14:53
@primer-cssprimer-css mentioned this pull request Nov 2, 2022
Sign up for freeto 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

@joshblack@josepmartins