Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen when CommandItem is Highlighted #319

Open
orlandodiaz opened this issue Oct 22, 2024 · 1 comment
Open

Listen when CommandItem is Highlighted #319

orlandodiaz opened this issue Oct 22, 2024 · 1 comment

Comments

@orlandodiaz
Copy link

I want to conditionally render a different JSX based on whether the CommandItem is highlighted (not clicked). i.e mouse over or selected via using the arrow keys where we see the bg change

I don't see this being possible at the moment

Only thing I was able to find was doing something like this

[cmdk-item][data-selected] {
outline: 1px solid black;
}

but this only applies CSS. I want to conditionally apply different JSX and do more than just styling

@Lexachoc
Copy link

You can track the aria-selected or data-selected boolean values using MutationObserver.

I think the example in here could help.
Which is the Model HoverCard showed in the Playground.

Then you may also need to check the [PR] (shadcn-ui/ui#5382), which fixes the bugs of the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants