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

Apply sx prop to Select's parent for custom styles #3888

Merged
merged 4 commits into from
Nov 2, 2023

Conversation

strackoverflow
Copy link
Member

Closes #3599

This PR fixes a bug where the sx prop for the Select component didn't have any effect.

Given the following custom styles, here is the before/after:

<Select sx={{borderRadius: '12px', border: '1px dashed #000000'}}>
Before After
before after

It seems as though the custom styles need to be applied to the TextInputWrapper component rather than the StyledSelect component, but I'm wondering if there are any drawbacks or complications from applying all of the custom styles to this element.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan

Testing & Reviewing

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@strackoverflow strackoverflow requested review from a team and siddharthkp October 31, 2023 16:30
Copy link

changeset-bot bot commented Oct 31, 2023

🦋 Changeset detected

Latest commit: ecefb0a

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

Copy link
Contributor

github-actions bot commented Oct 31, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 104.06 KB (+0.01% 🔺)
dist/browser.umd.js 104.61 KB (+0.01% 🔺)

@strackoverflow strackoverflow temporarily deployed to github-pages October 31, 2023 16:36 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3888 October 31, 2023 16:37 Inactive
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Almost there! Just a tiny change needed

src/Select.tsx Outdated
@@ -81,6 +84,7 @@ const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
fill: disabled ? 'GrayText' : 'FieldText',
},
},
...sx,
Copy link
Member

Choose a reason for hiding this comment

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

Hi! This is 99% there.

...sx does a shallow merge with the existing styles so it might accidentally override nested style objects. We have a merge utility for sx that deep merges. Here is a another component that uses merge for reference.


For example, with shallow merge:

<Select sx={{
 '@media screen and (forced-colors: active)': {
    color: 'fg.muted'
 }
}}>

...props.sx will completely overwrite the '@media screen and (forced-colors: active)' key and remove svg styles

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Makes sense!

@siddharthkp
Copy link
Member

⚠️ No Changeset found

Here's the format we follow for changesets:

---
"@primer/react": patch
---

Select: Add support for `sx` prop

<!-- Changed components: Select -->

@strackoverflow strackoverflow temporarily deployed to github-pages November 1, 2023 16:01 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3888 November 1, 2023 16:01 Inactive
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Looks great!

Feel free to merge it whenever you're ready!

@strackoverflow strackoverflow added this pull request to the merge queue Nov 2, 2023
Merged via the queue into main with commit 3e20ab1 Nov 2, 2023
29 checks passed
@strackoverflow strackoverflow deleted the select-sx-prop branch November 2, 2023 15:47
@primer primer bot mentioned this pull request Nov 2, 2023
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.

Unable to style Select with sx prop
2 participants