ui icon indicating copy to clipboard operation
ui copied to clipboard

ComboBox Does Not Highlight Selected Option

Open designcise opened this issue 1 year ago • 3 comments

As you can see in the following example, when the ComboBox is open, it always highlights the first option in the list and not the selected one:

Screenshot 2024-01-27 at 12 58 44 AM

This seems to also be the case with the Command component. Is there a workaround to ensure that the correct/selected item is highlighted by default when the list is visible?

designcise avatar Jan 27 '24 00:01 designcise

Here is an example of mine, as you can see the select one has an icon on the left.

This style that you are talking about is the cursor position, and it's happen because you can use keyboard arrow to select, and it shows the user what item is "hover"

Can you please share a reproducible example to try and help you with this?

Screenshot 2024-01-27 at 21 49 54

brunocroh avatar Jan 28 '24 00:01 brunocroh

I was referring to the "grey" background that highlights the first item always.. it gives the impression that the first item is active .. should the previously active item not be the one to have the grey background by default when the list is expanded?

Also, can you share the code you used to get the checkmark against the selected item? Thanks!

designcise avatar Jan 28 '24 02:01 designcise

I was referring to the "grey" background that highlights the first item always.. it gives the impression that the first item is active .. should the previously active item not be the one to have the grey background by default when the list is expanded?

Also, can you share the code you used to get the checkmark against the selected item? Thanks!

I think he maybe do it something like this:

<CheckIcon className={cn( "ml-auto h-4 w-4", value === framework.value ? "opacity-100" : "opacity-0" )} />

You can also, check the code for the examples they put on shadcn-ui website in : https://ui.shadcn.com/docs/components/combobox

Cauatn avatar Feb 05 '24 13:02 Cauatn

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 28 '24 23:02 shadcn

Also i'm having the same problem, i'm trying to highlight the selected item but rather when you open the PopoveContent you get the first element highlighted image

h-bijjou-binairy avatar Mar 04 '24 11:03 h-bijjou-binairy

Also i'm having the same problem, i'm trying to highlight the selected item but rather when you open the PopoveContent you get the first element highlighted image

Go to your shadcn components folder on dropdown-menu.tsx file, remove these classNames focus:bg-accent focus:text-accent-foreground from DropdownMenuItem component.

If you want style when mouse hover, just change focus: to hover:

brunocroh avatar Mar 04 '24 13:03 brunocroh

This is not the dropdownMenuItem component issue. This is a specific in the cmdk package, it auto highlight the first item always. there is no specific way for now to highlight the selected item. Unless someone has a better alternative.

minedun6 avatar Jul 15 '24 10:07 minedun6