freenowtech / wave

Design System of FREE NOW
https://wave.free-now.com
Apache License 2.0
64 stars 23 forks source link

Applying custom styling to SelectList component overrides other styling #219

Open jonotrujillo opened 2 years ago

jonotrujillo commented 2 years ago

Relevant code

When applying custom styles to the SelectList component using the styles API from react-select, other styles get overwritten.

For example:

<SelectList
  id="select-list-playground"
  isMulti
  hideSelectedOptions={false}
  styles={{
  option: (css, state) => ({
    ...css,
    position: 'relative',
    ...(state.isSelected && {
      '::after': {
        content: '" (selected)"',
      },
    }),
  }),
}}
  label="City"
  onChange={change => console.log(change)}
  options={[
    {
      label: 'Barcelona',
      value: 'bcn',
    },
    {
      label: 'Hamburg',
      value: 'ham',
    },
    {
      label: 'Paris',
      value: 'par',
      isDisabled: true,
    },
  ]}
/>

Produces a select list that looks like this, where the style is overwritten for the pills, disabled state, height of the select list...

Screenshot 2022-05-03 at 11 34 49

Our use case for applying custom styling to the option is that we want to show the "(selected)" text next to the selected ones, to help the user navigate the options. We are currently doing this with JS, but we can simplify the code a lot if custom css was supported here.

What was expected to happen?

Styles should be merged?

Reproduction

https://codesandbox.io/s/wave-playground-forked-oq8jpd?file=/src/App.js

bluessista commented 2 years ago
Screenshot 2022-05-03 at 11 50 47

I like this request as it also affects our case were we want the mandatory option in a multi select not to be clearable.

rafael-sepeda commented 2 years ago

The "Fixed" option is already part of the original React Select component that we use as a basis. So it should be possible to use this. We also have a tag component with dismissible={false} option https://wave.free-now.com/components/tag