Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ type GroupProps = Children &
/** Whether this group is forcibly rendered regardless of filtering. */
forceMount?: boolean
}
type InputProps = Omit<React.ComponentPropsWithoutRef<typeof Primitive.input>, 'value' | 'onChange' | 'type'> & {
type InputProps = Omit<React.ComponentPropsWithoutRef<typeof Primitive.input>, 'value' | 'onChange'> & {
/**
* Optional controlled state for the value of the search input.
*/
value?: string
/**
* Event handler called when the search value changes.
*/
onValueChange?: (search: string) => void
onValueChange?: (search: string) => void,
type?: React.InputHTMLAttributes<HTMLInputElement>['type']
}
type CommandFilter = (value: string, search: string, keywords?: string[]) => number
type CommandProps = Children &
Expand Down Expand Up @@ -288,7 +289,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
})
}
},
// Track item lifecycle (mount, unmount)
// Track item lifecycle(mount, unmount)
item: (id, groupId) => {
allItems.current.add(id)

Expand Down Expand Up @@ -333,6 +334,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
})
}
},

// Track group lifecycle (mount, unmount)
group: (id) => {
if (!allGroups.current.has(id)) {
Expand Down Expand Up @@ -514,8 +516,8 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
index + change < 0
? items[items.length - 1]
: index + change === items.length
? items[0]
: items[index + change]
? items[0]
: items[index + change]
}

if (newSelected) store.setState('value', newSelected.getAttribute(VALUE_ATTR))
Expand Down Expand Up @@ -785,7 +787,7 @@ const Separator = React.forwardRef<HTMLDivElement, SeparatorProps>((props, forwa
* All props are forwarded to the underyling `input` element.
*/
const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRef) => {
const { onValueChange, ...etc } = props
const { onValueChange, type = 'text', ...etc } = props
const isControlled = props.value != null
const store = useStore()
const search = useCmdk((state) => state.search)
Expand Down Expand Up @@ -813,7 +815,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRe
aria-labelledby={context.labelId}
aria-activedescendant={selectedItemId}
id={context.inputId}
type="text"
type={type}
value={isControlled ? props.value : search}
onChange={(e) => {
if (!isControlled) {
Expand All @@ -822,6 +824,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRe

onValueChange?.(e.target.value)
}}

/>
)
})
Expand Down