One challenge I am facing is reusing an n dropdown input element in various parts of different applications. This dropdown input element contains options with dropdowns nested within it, and the number of dropdowns can vary. For example:
https://i.sstatic.net/diia5.png
I want to apply styling based on a class
react-select-2-option-[indexOfTheOptionWithDropdown]
. For instance, the dynamic css class for Sydney 333
would be react-select-2-option-2
because it's the second dropdown element in the input field.
Similarly, Sydney 333222
would have a dynamic class of react-select-2-option-1
.
The problem arises when trying to assign indices to these classes based on the length and position of the dropdown options. The default styles applied by the 'react-select' library are difficult to override, so hardcoding the values seems like a static solution. Is there a more dynamic approach?
In my JSX component, I'm mapping the options along with index numbers. Ideally, I would like to somehow pass this index from the JSX component to the CSS file. Is this feasible? Should I consider using styled CSS components and passing the index to overwrite the CSS, or are there other methods to achieve this?
EDIT:
I hardcoded react-select-2-option-4:hover
with white background
https://i.sstatic.net/161WW.png
default style (options with grey background, no indication of hover) https://i.sstatic.net/sAHOp.png