Feature Request: Allow multiple classNamePrefixes #4486
Replies: 5 comments 2 replies
-
In my opinion this does not need a change in the source code. You can easily achieve the same thing using a combination of .prefixed__control {
background: red;
}
.withClass .prefixed__control {
background: blue;
} <Select classNamePrefix="prefixed" />
<Select classNamePrefix="prefixed" className="withClass" /> |
Beta Was this translation helpful? Give feedback.
-
@Rall3n Hello, |
Beta Was this translation helpful? Give feedback.
-
Greetings @andrew-aladev from an everyday user who prefers stylesheets to styled components. First of all,
Take this example from the Discussions Code Gallery: It exemplifies a common use case of wanting to apply some modifier from the parent applied to the other custom components. In this case an inline react-select is given the className Base class If you wanted more customization, eg: const Menu = props => <components.Menu className="a-in-b-custom-menu" {...props} />
const MySelect = props => <Select components={{ Menu }} {...props} /> .a-in-b-custom-menu { /* css stuff */ } As a roadmap note, Jed has expressed interest in creating an api similar to styles but for component classNames to make it easier for those using UI libraries like Tailwind to style components exclusively using classNames. Please lt me know if any of this helps, or please provide some example that is not satisfied by what @Rall3n or myself have responded with. |
Beta Was this translation helpful? Give feedback.
-
@ebonow, Hello. There is a special option: in portaling docs: Custom components is a good solution, but not universal. If first developer implemented custom |
Beta Was this translation helpful? Give feedback.
-
Good point regarding portalling. A custom MenuPortal would likely be needed to pass in some derived className perhaps even passed in as a custom selectProp. const MenuPortal = props =>
<components.MenuPortal className={props.selectProps.menuPortalClassName} {...props} /> From there, writing a Menu/Option styling mixin for Sass would likely be a way to make it easier to address these custom use cases. To your concerns about being universal, my preference is that there is a base Select that everyone uses with agreed standards so that users do not need to re-engineer similar custom components. I suppose this is simply a personal preference, but I prefer to abstract my implementation away from the base component to either swap out later or add new functionality that I want shared among all my selects. For example, I prefer the idea of a floating label as opposed to a Placeholder component, and instead pass the placeholder as an attribute to the input when the user focuses on it (blur removes it to avoid overlap). It wouldn't make sense to import and pass this custom Input component to every one of my 100+ Selects, but again to each their own. That all said, this seems to come down to personal preference and convenience and not so much an actual issue so I will rename this title and have it converted to a Feature Request discussion. Perhaps this will be addressed in the discussed as a future roadmap item as we look at how to apply classNames to components without the need for writing a custom component simply to pass in a new className. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Please refer issue 4230.
classNamePrefix="react-select"
is not enough for everyday react select styles customization.react-select
can be used in separate component with its own styles together with styles for parent component. Please add ability to useclassNamePrefixes={["react-select", "react-select__for-component-x"]}
.Developers don't want to use
styled components
of other inline styles solutions for political reasons. We have seen enough projects where styles was mixed with business logic inside single javascript file. We have spent a lot of time on refactoring unmaintainable code: inline styles always ends badly.For now there is only one available workaround: use
classNamePrefix="react-select__for-component-x"
and.react-select__for-component-x { @extend .react-select }
. But this solution is not acceptable from the following perspective:User of component
A
is able to customize<div class="a my-class-name">
by adding class name. But user is not able to customize<select>
. Please imagine that we need to customize componentA
from componentB
:We can see that developer of
B
component have to know implementation of componentA
to properly extend his classreact-select__for-a-inside-b
withreact-select__for-a
(internal class for componentA
).And vice versa: developer of
A
component can't renamereact-select__for-a
class name prefix without touching other components (likeB
).Please review the following proposed solution:
Every developer implements its own component and know nothing about other components (except its interfaces).
If you will accept this solution, i can prepare a pull request, thank you.
Beta Was this translation helpful? Give feedback.
All reactions