From 5d9d6e32c96ac240559d7767b6fe73f7223807ad Mon Sep 17 00:00:00 2001 From: Sid Jain Date: Wed, 30 Oct 2024 23:55:45 +0530 Subject: [PATCH] fix(context): read disablePointerSelection from propsRef (#314) * use latest value from ref * rename context method --------- Co-authored-by: paco <34928425+pacocoursey@users.noreply.github.com> --- cmdk/src/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index 6f4c9e0..e135750 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -123,7 +123,7 @@ type Context = { group: (id: string) => () => void filter: () => boolean label: string - disablePointerSelection: boolean + getDisablePointerSelection: () => boolean // Ids listId: string labelId: string @@ -343,7 +343,9 @@ const Command = React.forwardRef((props, forwarded return propsRef.current.shouldFilter }, label: label || props['aria-label'], - disablePointerSelection, + getDisablePointerSelection: () => { + return propsRef.current.disablePointerSelection + }, listId, inputId, labelId, @@ -705,7 +707,7 @@ const Item = React.forwardRef((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}