Styling selected option, disables :hover on the other options
Hi there,
I'm currently trying to change the color of a selected option in the dropdown. Editing the background color itself, seems alright. But it seems to "disable" the other options when I hover over them. Is this by design? or is it a bug? Or maybe I'm just doing it all wrong?
Codesandbox: https://codesandbox.io/s/kw1qw4l3n7
@linda94, it takes a bit of learning to understand how emotion styles work but they are super powerful and can cover all possible cases. You are in fact overriding all non-selected background colors to "". The component is already calculating what background-color to supply based on the hover state so you can just pass that as the default if not selected.
backgroundColor: state.isSelected ? "red" : styles.backgroundColor,
https://codesandbox.io/s/xzv62vo8kw
Please close this issue if there are no other questions and next time please use stackOverflow for any questions on implementation please.
@linda94 Actually, you can simply apply the initial styles back to the overridden option styles using
option: (styles, state) => ({
...styles,
backgroundColor: state.isSelected ? "red" : "",
"&:hover": { // overriding hover
...styles, // apply initial styles
},
})
https://codesandbox.io/s/react-codesandboxer-example-forked-n6tqtk?file=/example.js
styles={{
control: (base) => ({
...base,
border: `1px solid #e5e7eb`,
borderRadius: "0.5rem",
boxShadow: "none",
"&:hover": {
border: "1px solid #f6bf63cc",
},
}),
}}