Skip to content

Commit def1ac6

Browse files
committed
made search work with enterkey (huge)
1 parent f6c93fb commit def1ac6

File tree

1 file changed

+20
-5
lines changed
  • packages/react/src/components/header/searchbar/components

1 file changed

+20
-5
lines changed

packages/react/src/components/header/searchbar/components/SearchBar.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { CommandList, Command as CommandPrimitive } from "cmdk";
2-
import { Command, CommandGroup, CommandShortcut } from "@/shadcn/ui/command";
2+
import {
3+
Command,
4+
CommandGroup,
5+
CommandItem,
6+
CommandShortcut,
7+
} from "@/shadcn/ui/command";
38
import { cn } from "@/lib/utils";
49
import {
510
queryAtom,
@@ -139,10 +144,12 @@ export function SearchBar({
139144
className="ml-2 flex-1 bg-transparent outline-none placeholder:text-base-8"
140145
/>
141146
<div className="ml-auto flex flex-row opacity-0 group-focus-within:opacity-100 ">
142-
<CommandShortcut className="pointer-events-none opacity-80">
143-
<span className="mr-1 rounded-sm bg-base-4 p-0.5"></span>
144-
<span className="rounded-sm bg-base-4 p-0.5"></span>
145-
</CommandShortcut>
147+
{query.length > 0 && (
148+
<CommandShortcut className="pointer-events-none opacity-80">
149+
{/* <span className="mr-1 rounded-sm bg-base-4 p-0.5">⇪</span> */}
150+
<span className="rounded-sm bg-base-4 p-0.5"></span>
151+
</CommandShortcut>
152+
)}
146153
<button
147154
type="submit"
148155
className="-my-2 -mr-1 flex size-8 items-center rounded-md text-base-11 transition-all hover:bg-base-5 hover:text-primary-11"
@@ -193,6 +200,14 @@ export function SearchBar({
193200
</div>
194201
}
195202
>
203+
{query.length > 0 && (
204+
// Add a dummy item to make the <enter> key search by default.
205+
<CommandItem
206+
onSelect={doSearch}
207+
className="hidden"
208+
value="-"
209+
/>
210+
)}
196211
{autocomplete.map((item) => {
197212
return (
198213
<AutocompleteDropdownItem

0 commit comments

Comments
 (0)