Skip to content

Commit

Permalink
fix(context): read disablePointerSelection from propsRef (#314)
Browse files Browse the repository at this point in the history
* use latest value from ref

* rename context method

---------

Co-authored-by: paco <[email protected]>
  • Loading branch information
f0rr0 and pacocoursey authored Oct 30, 2024
1 parent 0bd1fe2 commit 5d9d6e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type Context = {
group: (id: string) => () => void
filter: () => boolean
label: string
disablePointerSelection: boolean
getDisablePointerSelection: () => boolean
// Ids
listId: string
labelId: string
Expand Down Expand Up @@ -343,7 +343,9 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
return propsRef.current.shouldFilter
},
label: label || props['aria-label'],
disablePointerSelection,
getDisablePointerSelection: () => {
return propsRef.current.disablePointerSelection
},
listId,
inputId,
labelId,
Expand Down Expand Up @@ -705,7 +707,7 @@ const Item = React.forwardRef<HTMLDivElement, ItemProps>((props, forwardedRef) =
aria-selected={Boolean(selected)}
data-disabled={Boolean(disabled)}
data-selected={Boolean(selected)}
onPointerMove={disabled || context.disablePointerSelection ? undefined : select}
onPointerMove={disabled || context.getDisablePointerSelection() ? undefined : select}
onClick={disabled ? undefined : onSelect}
>
{props.children}
Expand Down

0 comments on commit 5d9d6e3

Please sign in to comment.