How to style react-select responsive

43 Views Asked by At

I am new at using react-select library and I need to add a responsive styling to creatable component and I don't know how. Can you please show me an example in order to know better the syntax ?

input: (provided) => ({ ...provided, marginLeft: '8px', color: 'var(--center-channel-color)', })

I don't know the syntax

1

There are 1 best solutions below

0
BetterReact Developer On BEST ANSWER

To add responsive styling to a Creatable component in react-select, you can use the styles prop to customize the appearance of different parts of the select component. Here's an example of how you can use the styles prop to apply custom styles to a Creatable component:

import React from "react";
import CreatableSelect from "react-select/creatable";

const customStyles = {
  control: (provided, state) => ({
    ...provided,
    marginLeft: "8px",
    marginTop: "10px",
    color: state.isFocused ? "var(--center-channel-color)" : "initial",
  }),
};

const App = () => {
  return (
    <CreatableSelect
      styles={customStyles}
      options={[{ value: "chocolate", label: "Chocolate" }]} // Example options
    />
  );
};

export default App;

You can customize other parts of the Creatable component, such as menu, option, input, etc., by adding more styles to the customStyles object. Each style key corresponds to a different part of the Creatable component.

For reference- https://react-select.com/home#fixed-options