File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
packages/components/src/ui Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ export interface SelectProps<T extends React.Key = string>
5757
5858// Default search input built on top of CommandInput. Supports cmdk props at runtime.
5959const DefaultSearchInput = forwardRef < HTMLInputElement , React . ComponentPropsWithoutRef < typeof CommandInput > > (
60- ( props , _ref ) => < CommandInput { ...props } /> ,
60+ ( props , ref ) => < CommandInput { ...props } /> ,
6161) ;
6262DefaultSearchInput . displayName = 'SelectSearchInput' ;
6363
@@ -97,8 +97,16 @@ export function Select<T extends React.Key = string>({
9797 return ;
9898 }
9999 requestAnimationFrame ( ( ) => {
100- if ( searchable && searchInputRef . current ) {
101- searchInputRef . current . focus ( ) ;
100+ if ( searchable ) {
101+ // Query for the input element since CommandInput uses asChild and ref forwarding is complex
102+ const inputElement = popoverRef . current ?. querySelector < HTMLInputElement > ( 'input[type="text"]' ) ;
103+ if ( inputElement ) {
104+ inputElement . focus ( ) ;
105+ const selectionEnd = inputElement . value . length ;
106+ if ( selectionEnd > 0 ) {
107+ inputElement . setSelectionRange ( selectionEnd , selectionEnd ) ;
108+ }
109+ }
102110 }
103111 const selectedEl = selectedItemRef . current as HTMLElement | null ;
104112 if ( selectedEl ) selectedEl . scrollIntoView ( { block : 'center' } ) ;
You can’t perform that action at this time.
0 commit comments