react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Styling selected option, disables :hover on the other options

Open linda94 opened this issue 7 years ago • 3 comments

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 avatar Jan 11 '19 13:01 linda94

@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.

c-moss-talk avatar Mar 07 '19 20:03 c-moss-talk

@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

Mitesh13499 avatar Jul 19 '22 13:07 Mitesh13499

  styles={{
                      control: (base) => ({
                        ...base,
                        border: `1px solid #e5e7eb`,
                        borderRadius: "0.5rem",
                        boxShadow: "none",
                        "&:hover": {
                          border: "1px solid #f6bf63cc",
                        },
                      }),
                    }}

daxdesai avatar Mar 19 '24 04:03 daxdesai