@@ -3,7 +3,8 @@ import {isFocusable} from '@primer/behaviors/utils'
33import { omit } from '@styled-system/props'
44import React , { FocusEventHandler , KeyboardEventHandler , MouseEventHandler , RefObject , useRef , useState } from 'react'
55import Box from './Box'
6- import { useRefObjectAsForwardedRef } from './hooks/useRefObjectAsForwardedRef'
6+ import { useProvidedRefOrCreate } from './hooks'
7+ import { useCombinedRefs } from './hooks/useCombinedRefs'
78import { useFocusZone } from './hooks/useFocusZone'
89import Text from './Text'
910import { TextInputProps } from './TextInput'
@@ -92,11 +93,12 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
9293 visibleTokenCount,
9394 ...rest
9495 } : TextInputWithTokensProps < TokenComponentType > ,
95- forwardedRef : React . ForwardedRef < HTMLInputElement >
96+ externalRef : React . ForwardedRef < HTMLInputElement >
9697) {
9798 const { onBlur, onFocus, onKeyDown, ...inputPropsRest } = omit ( rest )
98- const ref = useRef < HTMLInputElement > ( null )
99- useRefObjectAsForwardedRef ( forwardedRef , ref )
99+ const ref = useProvidedRefOrCreate < HTMLInputElement > ( externalRef as React . RefObject < HTMLInputElement > )
100+ const localInputRef = useRef < HTMLInputElement > ( null )
101+ const combinedInputRef = useCombinedRefs ( localInputRef , ref )
100102 const [ selectedTokenIndex , setSelectedTokenIndex ] = useState < number | undefined > ( )
101103 const [ tokensAreTruncated , setTokensAreTruncated ] = useState < boolean > ( Boolean ( visibleTokenCount ) )
102104 const { containerRef} = useFocusZone (
@@ -122,7 +124,7 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
122124 }
123125
124126 if ( nextIndex > tokens . length || nextIndex < 1 ) {
125- return ref . current || undefined
127+ return combinedInputRef . current || undefined
126128 }
127129
128130 return containerRef . current ?. children [ nextIndex ] as HTMLElement
@@ -228,7 +230,7 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
228230 }
229231
230232 const focusInput : MouseEventHandler = ( ) => {
231- ref . current ?. focus ( )
233+ combinedInputRef . current ?. focus ( )
232234 }
233235
234236 const preventTokenClickPropagation : MouseEventHandler = event => {
@@ -321,7 +323,7 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
321323 } }
322324 >
323325 < UnstyledTextInput
324- ref = { ref }
326+ ref = { combinedInputRef }
325327 disabled = { disabled }
326328 onFocus = { handleInputFocus }
327329 onBlur = { handleInputBlur }
0 commit comments