Skip to content

Commit ed85694

Browse files
refactor(web): add an active prop to CommandItem (pingdotgg#13023)
Co-authored-by: Claude Fable 5 <[email protected]>
1 parent ce98d41 commit ed85694

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎apps/web/src/components/CommandPaletteResults.tsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
CommandShortcut,
1616
} from "./ui/command";
1717
import { ThreadSearchMatchExcerpt } from "./ThreadSearchMatch";
18-
import { cn } from "~/lib/utils";
1918

2019
interface CommandPaletteResultsProps {
2120
emptyStateMessage?: string;
@@ -109,10 +108,8 @@ function CommandPaletteResultRow(props: {
109108
return (
110109
<CommandItem
111110
value={props.item.value}
112-
className={cn(
113-
"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",
114-
props.isActive && "bg-accent! text-accent-foreground!",
115-
)}
111+
active={props.isActive}
112+
className="gap-2"
116113
onMouseDown={(event) => {
117114
event.preventDefault();
118115
}}

‎apps/web/src/components/chat/ComposerCommandMenu.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
161161
<CommandItem
162162
value={props.item.id}
163163
data-composer-item-id={props.item.id}
164-
className={cn(
165-
"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",
166-
props.isActive && "bg-accent! text-accent-foreground!",
167-
)}
164+
active={props.isActive}
165+
className="gap-3 rounded-lg px-3 py-2!"
168166
onMouseMove={() => {
169167
if (!props.isActive) props.onHighlight(props.item.id);
170168
}}

‎apps/web/src/components/ui/command.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,24 @@ function CommandCollection({ ...props }: React.ComponentProps<typeof Autocomplet
160160
return <AutocompleteCollection data-slot="command-collection" {...props} />;
161161
}
162162

163-
function CommandItem({ className, ...props }: React.ComponentProps<typeof AutocompleteItem>) {
163+
// Pass `active` when the palette tracks the highlighted row itself; the
164+
// primitive's hover and keyboard highlight are then ignored so the two never
165+
// disagree, and the row shows the active surface instead.
166+
function CommandItem({
167+
className,
168+
active,
169+
...props
170+
}: React.ComponentProps<typeof AutocompleteItem> & { active?: boolean }) {
164171
return (
165172
<AutocompleteItem
166173
className={cn(
167174
"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",
175+
active !== undefined &&
176+
"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",
177+
active && "bg-accent! text-accent-foreground!",
168178
className,
169179
)}
180+
data-active={active || undefined}
170181
data-slot="command-item"
171182
{...props}
172183
/>

‎scripts/lint-restyle-ceiling.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as NodeURL from "node:url";
88
// components/ui exports are migrated to variants (see vite.config.ts). This gate keeps the
99
// count from growing: CI fails when findings exceed the ceiling. Lower the ceiling when you
1010
// migrate a file, and delete this script when the rule becomes an error.
11-
export const RESTYLE_CEILING = 1159;
11+
export const RESTYLE_CEILING = 1143;
1212

1313
const RULE = "shadcn(no-restyle)";
1414

0 commit comments

Comments
 (0)