Skip to content
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(Select): move selected from <option> to defaultValue on <select> #2511

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

joshblack
Copy link
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 after defaultValue

@joshblack joshblack requested review from a team and josepmartins November 1, 2022 18:26
@changeset-bot
Copy link

changeset-bot bot commented Nov 1, 2022

🦋 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
Name Type
@primer/react Patch

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
Copy link
Contributor

github-actions bot commented Nov 1, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 78.82 KB (+0.01% 🔺)
dist/browser.umd.js 79.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
Copy link
Contributor

@josepmartins josepmartins left a comment

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 main Nov 2, 2022
@joshblack joshblack deleted the fix/update-select-placeholder branch November 2, 2022 14:53
@primer-css primer-css mentioned this pull request Nov 2, 2022
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