-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Unable to style react-select component with styled-components v6 #4074
Comments
I believe this is caused by the |
That's correct @pankajpatel but is there any solution to this? |
Hello @dogfootruler-kr ,
that way the react-select theme is passed to react-select via styled-component and not used by it |
Hello @CyrilQuandalle and thank you for your example but sadly I still have an error when opening the select. I made a new sandbox with your code change: Do you use a different react-select version maybe? |
Hello @dogfootruler-kr , |
I'm sorry I completely forgot to mention I was using styled-components v6. |
It's ok, it's actually on me because I didn't read that you were using SC version 6 in the description of your issue |
Do we know why the "theme" prop is being removed by the styled-components wrapper since v6? When I revert that single change, as done in the PR #4129, both styled-componets@6.1.0 and react-select@5.7.7 are working together perfectly. |
Here's a simple sandbox to show the issue: https://codesandbox.io/p/sandbox/eloquent-morning-gv6p4k. As a workaround specifically for react-select with default themes, it is possible to import |
A solution to recover the eaten import {components, defaultTheme, SingleValueProps} from "react-select";
function Inner(props: SingleValueProps) {
return (
<components.SingleValue theme={defaultTheme} {...props}>
{props.children}
</components.SingleValue>
)
}
const SingleValue = styled(Inner)`
// custom styling…
`;
export default SingleValue; As I do all styling with styled-components, I don't dependent on the integrated styling mechanism of react-select. |
Any chances to see a fix in |
Fixed the specific scenario documented in #4074.
Fixed the specific scenario documented in #4074.
Fixed the specific scenario documented in #4074.
This issue is fixed in 6.1.4 when using I don't think we can let |
@quantizor What is the right way to fix it in this code? import React from "react";
import Select from "react-select";
import styled from "styled-components";
import { components } from "react-select";
const optionsArray = [
{ value: "o1", label: "option 1" },
{ value: "o2", label: "option 2" },
];
const StyledControl = styled(components.Control)`
border: 1px solid red;
`;
const SelectControl = (props) => {
console.log("props.theme", props.theme);
return <StyledControl {...props} />;
};
export default () => (
<Select
components={{ Control: SelectControl }}
value={[{ value: "o1", label: "option 1" }]}
options={optionsArray}
/>
); Sandbox: https://codesandbox.io/p/sandbox/codesandboxer-example-forked-l7s2ny?file=%2Fexample.tsx%3A18%2C6 As you can see, we don't use If the problem is in name collision maybe it could be solved by adding some global parameter with the alternative name for the |
I provided the setup in the forked sandbox I linked in my comment. You need to provide the theme as a different prop and then alias it inside attrs |
@quantizor But in my case I don't use theme functionality at all. Should I add it just to workaround this case, do it in many places and keep it in mind adding any new select sub-components? Maybe there is a better solution? Can we do it globally somehow? |
I think ultimately the right fix is to deprecate passing a styled-components |
@quantizor That would be better too especially now when all props without '$' prefix are passed to original component. I had to restore original logic using |
Environment
Reproduction
https://codesandbox.io/s/styled-component-with-react-select-wsd87q
Steps to reproduce
Styling a components.ValueContainer from react-select is impossible as it expects a
theme
prop that is removed by styled-components.Expected Behavior
Possible to style react-select
Actual Behavior
Impossible to style react-select
The text was updated successfully, but these errors were encountered: