Skip to content

Change text-color when isFocused && isSelected is true in custom implementation of ComboBox? #2787

Discussion options

You must be logged in to vote

Found the solution thanks to some guy on Reddit. Had to do isSelected && !isFocused:

<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

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@snowystinger
Comment options

@LFDanLu
Comment options

LFDanLu Feb 1, 2022
Collaborator

@deadcoder0904
Comment options

@LFDanLu
Comment options

LFDanLu Feb 2, 2022
Collaborator

@deadcoder0904
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants