Reputation: 13108
We're using a custom Emotion component, and the documentation says that the same properties are passed to customer components, but they don't seem to be. isSelected
and other properties don't seem to be there either.
const Option = styled.div`
color: #444;
font-family: 'Open Sans', 'Arial', Sans-Serif !important;
font-size: 0.6875rem;
text-indent: 6px;
line-height: 1.85;
&:hover {
background: #9cbac2;
}
${props => {
return css`
background: ${props.isSelected ? 'red' : '#eee'}; // props.isSelected is not defined
`;
}}
`;
<Select
components={{
Option: ({ children, innerProps, innerRef }) => (
<Option ref={innerRef} {...innerProps}>
{children}
</Option>
),
}}
styles={reactSelectStyles} // Tried styling Option in the styles object, but that didn't work with a custom component
/>
Upvotes: 0
Views: 1695
Reputation: 202618
isSelected
prop is exposed to the Option
object, just need to pass it to your Option
component.
<Select
components={{
Option: ({ children, innerProps, innerRef, ...rest }) => (
<Option ref={innerRef} {...innerProps} {...rest}> // isSelected passed with `rest`
{children}
</Option>
)
}}
/>
Upvotes: 1