@@ -4,6 +4,8 @@ import { MagnifyingGlassIcon } from '@radix-ui/react-icons'
44import { Command as CommandPrimitive } from 'cmdk'
55import { Dialog , DialogContent } from '@/features/common/components/dialog'
66import { cn } from '../utils'
7+ import { XIcon } from 'lucide-react'
8+ import { Button } from '@/features/common/components/button'
79
810const Command = React . forwardRef < React . ElementRef < typeof CommandPrimitive > , React . ComponentPropsWithoutRef < typeof CommandPrimitive > > (
911 ( { className, ...props } , ref ) => (
@@ -30,10 +32,15 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
3032 )
3133}
3234
35+ const clearSearchButtonLabel = 'Clear search'
3336const CommandInput = React . forwardRef <
3437 React . ElementRef < typeof CommandPrimitive . Input > ,
35- React . ComponentPropsWithoutRef < typeof CommandPrimitive . Input >
36- > ( ( { className, ...props } , ref ) => (
38+ React . ComponentPropsWithoutRef < typeof CommandPrimitive . Input > & {
39+ // CmdK doesn't have the option to specify search type input
40+ // so we handle it ourselves
41+ onSearchClear ?: ( ) => void
42+ }
43+ > ( ( { className, onSearchClear, ...props } , ref ) => (
3744 < div className = "flex items-center px-3" cmdk-input-wrapper = "" >
3845 < MagnifyingGlassIcon className = "mr-2 size-4 shrink-0 opacity-50" />
3946 < CommandPrimitive . Input
@@ -44,6 +51,17 @@ const CommandInput = React.forwardRef<
4451 ) }
4552 { ...props }
4653 />
54+ { onSearchClear && (
55+ < Button
56+ onClick = { onSearchClear }
57+ variant = "no-style"
58+ size = "icon"
59+ aria-label = { clearSearchButtonLabel }
60+ className = { cn ( 'size-4 text-muted-foreground' ) }
61+ >
62+ < XIcon size = { '1rem' } />
63+ </ Button >
64+ ) }
4765 </ div >
4866) )
4967
0 commit comments