#Multiselect change selected value background dynamically

4 messages · Page 1 of 1 (latest)

azure zinc
#

Is this possible?

I have the follow code:

<MultiSelect
  data={[{ value: 'Dangerous', label: 'Dangerous', backgroundColor: '#C92A2A' }]}
  label="Tags"
  placeholder="Select tags"
  rightSection={<IconChevronDown size="1rem" />}
  rightSectionWidth={40}
  searchable
  creatable
  styles={{ value: { backgroundColor: '#C92A2A' } }}
  getCreateLabel={(query) => `+ Create ${query}`}
  onCreate={(query) => {
    const item = { value: query, label: query };
    return item;
  }}
/>         

But i want the styles to be like this: value: { backgroundColor: data.backgroundColor } or something in that order? Is that possible?

spare thunder
#

You can create your own wrapper component with something like:

const selected = props.data.find(item => item.value === props.value);
return (
<MultiSelect
  data={[{ value: 'Dangerous', label: 'Dangerous', backgroundColor: '#C92A2A' }]}
  label="Tags"
  placeholder="Select tags"
  rightSection={<IconChevronDown size="1rem" />}
  rightSectionWidth={40}
  searchable
  creatable
  styles={{ value: { backgroundColor: selected.backgroundColor } }}
  getCreateLabel={(query) => `+ Create ${query}`}
  onCreate={(query) => {
    const item = { value: query, label: query };
    return item;
  }}
/>  )
azure zinc
spare thunder