@@ -5,6 +5,7 @@ import * as React from 'react'
55import { commandScore } from './command-score'
66import { Primitive } from '@radix-ui/react-primitive'
77import { useId } from '@radix-ui/react-id'
8+ import { composeRefs } from '@radix-ui/react-compose-refs'
89import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'
910
1011type Children = { children ?: React . ReactNode }
@@ -703,7 +704,7 @@ const Item = React.forwardRef<HTMLDivElement, ItemProps>((props, forwardedRef) =
703704
704705 return (
705706 < Primitive . div
706- ref = { mergeRefs ( [ ref , forwardedRef ] ) }
707+ ref = { composeRefs ( ref , forwardedRef ) }
707708 { ...etc }
708709 id = { id }
709710 cmdk-item = ""
@@ -745,7 +746,7 @@ const Group = React.forwardRef<HTMLDivElement, GroupProps>((props, forwardedRef)
745746
746747 return (
747748 < Primitive . div
748- ref = { mergeRefs ( [ ref , forwardedRef ] ) }
749+ ref = { composeRefs ( ref , forwardedRef ) }
749750 { ...etc }
750751 cmdk-group = ""
751752 role = "presentation"
@@ -775,7 +776,7 @@ const Separator = React.forwardRef<HTMLDivElement, SeparatorProps>((props, forwa
775776 const render = useCmdk ( ( state ) => ! state . search )
776777
777778 if ( ! alwaysRender && ! render ) return null
778- return < Primitive . div ref = { mergeRefs ( [ ref , forwardedRef ] ) } { ...etc } cmdk-separator = "" role = "separator" />
779+ return < Primitive . div ref = { composeRefs ( ref , forwardedRef ) } { ...etc } cmdk-separator = "" role = "separator" />
779780} )
780781
781782/**
@@ -856,7 +857,7 @@ const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) =
856857
857858 return (
858859 < Primitive . div
859- ref = { mergeRefs ( [ ref , forwardedRef ] ) }
860+ ref = { composeRefs ( ref , forwardedRef ) }
860861 { ...etc }
861862 cmdk-list = ""
862863 role = "listbox"
@@ -866,7 +867,7 @@ const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) =
866867 id = { context . listId }
867868 >
868869 { SlottableWithNestedChildren ( props , ( child ) => (
869- < div ref = { mergeRefs ( [ height , context . listInnerRef ] ) } cmdk-list-sizer = "" >
870+ < div ref = { composeRefs ( height , context . listInnerRef ) } cmdk-list-sizer = "" >
870871 { child }
871872 </ div >
872873 ) ) }
@@ -998,21 +999,6 @@ function useLazyRef<T>(fn: () => T) {
998999 return ref as React . MutableRefObject < T >
9991000}
10001001
1001- // ESM is still a nightmare with Next.js so I'm just gonna copy the package code in
1002- // https://github.com/gregberge/react-merge-refs
1003- // Copyright (c) 2020 Greg Bergé
1004- function mergeRefs < T = any > ( refs : Array < React . MutableRefObject < T > | React . LegacyRef < T > > ) : React . RefCallback < T > {
1005- return ( value ) => {
1006- refs . forEach ( ( ref ) => {
1007- if ( typeof ref === 'function' ) {
1008- ref ( value )
1009- } else if ( ref != null ) {
1010- ; ( ref as React . MutableRefObject < T | null > ) . current = value
1011- }
1012- } )
1013- }
1014- }
1015-
10161002/** Run a selector against the store state. */
10171003function useCmdk < T = any > ( selector : ( state : State ) => T ) : T {
10181004 const store = useStore ( )
0 commit comments