Change text-color when isFocused && isSelected
is true
in custom implementation of ComboBox
?
#2787
-
I'd like to change the text color when both Here's my code: className={clsx(
'm-1 flex cursor-default items-center justify-between rounded-md py-2 px-2 text-sm outline-none',
{
'font-bold dark:text-indigo-500': isSelected,
'dark:bg-primary-dark dark:text-white': isFocused,
'dark:text-gray-400': !isFocused,
'dark:text-white': isSelected && isFocused,
}
)} I used the Codesandbox you've previously pointed to & re-created a demo without using
I'm not sure why the Another thing about |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I think your problem is with your tailwind setup, when I console log out isFocused and isSelected, they are correct. And if I change it to instead set bg-pink-300, I see that come through. I did find this, https://stackoverflow.com/questions/67098510/class-text-white-with-tailwind-does-not-work, so seems like a common thing to forget to add.
I'm not sure what you mean, do you mean when you open the combobox, focus isn't on the selected item? I think it's behaving as expected, with mouse, focus will follow the mouse. |
Beta Was this translation helpful? Give feedback.
-
@snowystinger i wasn't doing tailwind wrong. codesandbox has weird issues with tailwind dark mode & tailwind in general. faced this problem before too. had to remove all @LFDanLu here's my codesandbox demo that looks exactly like yours, just using |
Beta Was this translation helpful? Give feedback.
-
Found the solution thanks to some guy on Reddit. Had to do <li
{...optionProps}
ref={ref}
className={clsx(
'm-1 flex cursor-default items-center justify-between rounded-md py-2 px-2 text-sm outline-none',
{
'font-bold dark:text-indigo-500': isSelected && !isFocused,
},
{
'dark:bg-primary-dark dark:text-white': isFocused,
},
{
'dark:text-gray-400': !isFocused,
}
)}
>
{item.rendered}
{isSelected && (
<CheckIcon
aria-hidden="true"
className={clsx('h-5 w-5', {
'dark:text-indigo-500': !isFocused,
})}
/>
)}
</li> Codesandbox Demo → https://codesandbox.io/s/combobox-with-fzf-496ub?file=/src/ComboBox/ListBox.tsx |
Beta Was this translation helpful? Give feedback.
Found the solution thanks to some guy on Reddit. Had to do
isSelected && !isFocused
:Codesandbox Demo → https://codesandbox.io/s/combobox-with-fzf-496ub?file=/src/ComboBox/ListBox.tsx