Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override props #117

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
43 changes: 29 additions & 14 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { commandScore } from './command-score'
type Children = { children?: React.ReactNode }
type DivProps = React.HTMLAttributes<HTMLDivElement>

type LoadingProps = Children & {
/** Estimated progress of loading asynchronous options. */
progress?: number
}
type LoadingProps = Children &
DivProps & {
/** Estimated progress of loading asynchronous options. */
progress?: number
}
type EmptyProps = Children & DivProps & {}
type SeparatorProps = DivProps & {
/** Whether this separator should always be rendered. Useful if you disable automatic filtering. */
Expand Down Expand Up @@ -509,8 +510,8 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
return (
<div
ref={mergeRefs([ref, forwardedRef])}
{...etc}
cmdk-root=""
{...etc}
onKeyDown={(e) => {
etc.onKeyDown?.(e)

Expand Down Expand Up @@ -629,16 +630,30 @@ const Item = React.forwardRef<HTMLDivElement, ItemProps>((props, forwardedRef) =
return (
<div
ref={mergeRefs([ref, forwardedRef])}
{...etc}
id={id}
cmdk-item=""
role="option"
aria-disabled={disabled || undefined}
aria-selected={selected || undefined}
data-disabled={disabled || undefined}
data-selected={selected || undefined}
onPointerMove={disabled ? undefined : select}
onClick={disabled ? undefined : onSelect}
{...etc}
onPointerMove={
disabled
? etc.onPointerMove
: (event) => {
etc.onPointerMove?.(event)
select()
}
}
onClick={
disabled
? etc.onClick
: (event) => {
etc.onClick?.(event)
onSelect()
}
}
>
{props.children}
</div>
Expand Down Expand Up @@ -672,10 +687,10 @@ const Group = React.forwardRef<HTMLDivElement, GroupProps>((props, forwardedRef)
return (
<div
ref={mergeRefs([ref, forwardedRef])}
{...etc}
cmdk-group=""
role="presentation"
hidden={render ? undefined : true}
{...etc}
>
{heading && (
<div ref={headingRef} cmdk-group-heading="" aria-hidden id={headingId}>
Expand All @@ -699,7 +714,7 @@ const Separator = React.forwardRef<HTMLDivElement, SeparatorProps>((props, forwa
const render = useCmdk((state) => !state.search)

if (!alwaysRender && !render) return null
return <div ref={mergeRefs([ref, forwardedRef])} {...etc} cmdk-separator="" role="separator" />
return <div ref={mergeRefs([ref, forwardedRef])} cmdk-separator="" role="separator" {...etc} />
})

/**
Expand Down Expand Up @@ -728,7 +743,6 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRe
return (
<input
ref={forwardedRef}
{...etc}
cmdk-input=""
autoComplete="off"
autoCorrect="off"
Expand All @@ -741,6 +755,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRe
aria-activedescendant={selectedItemId}
id={context.inputId}
type="text"
{...etc}
value={isControlled ? props.value : search}
onChange={(e) => {
if (!isControlled) {
Expand Down Expand Up @@ -785,12 +800,12 @@ const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) =
return (
<div
ref={mergeRefs([ref, forwardedRef])}
{...etc}
cmdk-list=""
role="listbox"
aria-label="Suggestions"
id={context.listId}
aria-labelledby={context.inputId}
{...etc}
>
<div ref={height} cmdk-list-sizer="">
{children}
Expand Down Expand Up @@ -828,7 +843,7 @@ const Empty = React.forwardRef<HTMLDivElement, EmptyProps>((props, forwardedRef)
}, [])

if (isFirstRender.current || !render) return null
return <div ref={forwardedRef} {...props} cmdk-empty="" role="presentation" />
return <div ref={forwardedRef} cmdk-empty="" role="presentation" {...props} />
})

/**
Expand All @@ -840,13 +855,13 @@ const Loading = React.forwardRef<HTMLDivElement, LoadingProps>((props, forwarded
return (
<div
ref={forwardedRef}
{...etc}
cmdk-loading=""
role="progressbar"
aria-valuenow={progress}
aria-valuemin={0}
aria-valuemax={100}
aria-label="Loading..."
{...etc}
>
<div aria-hidden>{children}</div>
</div>
Expand Down