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

Fix suggestions list and loading progressbar labels #204

Merged
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
21 changes: 15 additions & 6 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type LoadingProps = Children &
DivProps & {
/** Estimated progress of loading asynchronous options. */
progress?: number
/**
* Accessible label for this loading progressbar. Not shown visibly.
*/
label?: string
}
type EmptyProps = Children & DivProps & {}
type SeparatorProps = DivProps & {
Expand All @@ -24,7 +28,13 @@ type DialogProps = RadixDialog.DialogProps &
/** Provide a custom element the Dialog should portal into. */
container?: HTMLElement
}
type ListProps = Children & DivProps & {}
type ListProps = Children &
DivProps & {
/**
* Accessible label for this List of suggestions. Not shown visibly.
*/
label?: string
}
type ItemProps = Children &
Omit<DivProps, 'disabled' | 'onSelect' | 'value'> & {
/** Whether this item is currently disabled. */
Expand Down Expand Up @@ -767,7 +777,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forwardedRe
* Use the `--cmdk-list-height` CSS variable to animate height based on the number of results.
*/
const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) => {
const { children, ...etc } = props
const { children, label = "Suggestions", ...etc } = props
const ref = React.useRef<HTMLDivElement>(null)
const height = React.useRef<HTMLDivElement>(null)
const context = useCommand()
Expand Down Expand Up @@ -797,9 +807,8 @@ const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) =
{...etc}
cmdk-list=""
role="listbox"
aria-label="Suggestions"
aria-label={label}
id={context.listId}
aria-labelledby={context.inputId}
>
<div ref={height} cmdk-list-sizer="">
{children}
Expand Down Expand Up @@ -844,7 +853,7 @@ const Empty = React.forwardRef<HTMLDivElement, EmptyProps>((props, forwardedRef)
* You should conditionally render this with `progress` while loading asynchronous items.
*/
const Loading = React.forwardRef<HTMLDivElement, LoadingProps>((props, forwardedRef) => {
const { progress, children, ...etc } = props
const { progress, children, label = "Loading...", ...etc } = props

return (
<div
Expand All @@ -855,7 +864,7 @@ const Loading = React.forwardRef<HTMLDivElement, LoadingProps>((props, forwarded
aria-valuenow={progress}
aria-valuemin={0}
aria-valuemax={100}
aria-label="Loading..."
aria-label={label}
>
<div aria-hidden>{children}</div>
</div>
Expand Down
Loading