refactor(web): add an active prop to CommandItem (#13023)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and GitHub committed 2026-09-22 12:22:11 -07:00
1 parent ce98d41077
commit ed856946c6
4 files changed
+17 -11

No files matched your search

@@ -15,7 +15,6 @@ import {
CommandShortcut,
} from "./ui/command";
import { ThreadSearchMatchExcerpt } from "./ThreadSearchMatch";
import { cn } from "~/lib/utils";
interface CommandPaletteResultsProps {
emptyStateMessage?: string;
@@ -109,10 +108,8 @@ function CommandPaletteResultRow(props: {
return (
<CommandItem
value={props.item.value}
className={cn(
"cursor-pointer gap-2 hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit data-selected:bg-transparent data-selected:text-inherit [&[data-highlighted][data-selected]]:bg-transparent [&[data-highlighted][data-selected]]:text-inherit",
props.isActive && "bg-accent! text-accent-foreground!",
)}
active={props.isActive}
className="gap-2"
onMouseDown={(event) => {
event.preventDefault();
}}
@@ -161,10 +161,8 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
<CommandItem
value={props.item.id}
data-composer-item-id={props.item.id}
className={cn(
"cursor-pointer select-none gap-3 rounded-lg px-3 py-2! hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
props.isActive && "bg-accent! text-accent-foreground!",
)}
active={props.isActive}
className="gap-3 rounded-lg px-3 py-2!"
onMouseMove={() => {
if (!props.isActive) props.onHighlight(props.item.id);
}}
+12 -1
View File
@@ -160,13 +160,24 @@ function CommandCollection({ ...props }: React.ComponentProps<typeof Autocomplet
return <AutocompleteCollection data-slot="command-collection" {...props} />;
}
function CommandItem({ className, ...props }: React.ComponentProps<typeof AutocompleteItem>) {
// Pass `active` when the palette tracks the highlighted row itself; the
// primitive's hover and keyboard highlight are then ignored so the two never
// disagree, and the row shows the active surface instead.
function CommandItem({
className,
active,
...props
}: React.ComponentProps<typeof AutocompleteItem> & { active?: boolean }) {
return (
<AutocompleteItem
className={cn(
"py-1.5 data-selected:bg-foreground/[0.06] data-highlighted:bg-foreground/[0.09] data-highlighted:text-foreground [&[data-highlighted][data-selected]]:bg-foreground/[0.09] [&[data-highlighted][data-selected]]:text-foreground",
active !== undefined &&
"cursor-pointer hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit data-selected:bg-transparent data-selected:text-inherit [&[data-highlighted][data-selected]]:bg-transparent [&[data-highlighted][data-selected]]:text-inherit",
active && "bg-accent! text-accent-foreground!",
className,
)}
data-active={active || undefined}
data-slot="command-item"
{...props}
/>
+1 -1
View File
@@ -8,7 +8,7 @@ import * as NodeURL from "node:url";
// components/ui exports are migrated to variants (see vite.config.ts). This gate keeps the
// count from growing: CI fails when findings exceed the ceiling. Lower the ceiling when you
// migrate a file, and delete this script when the rule becomes an error.
export const RESTYLE_CEILING = 1159;
export const RESTYLE_CEILING = 1143;
const RULE = "shadcn(no-restyle)";