@@ -6,6 +6,13 @@ import { Icon, type IconProps } from "./icon"
66import { IconButton } from "./icon-button"
77import { TextField } from "./text-field"
88
9+ function findByKey ( container : HTMLElement , key : string ) {
10+ const nodes = container . querySelectorAll < HTMLElement > ( '[data-slot="list-item"][data-key]' )
11+ for ( const node of nodes ) {
12+ if ( node . getAttribute ( "data-key" ) === key ) return node
13+ }
14+ }
15+
916export interface ListSearchProps {
1017 placeholder ?: string
1118 autofocus ?: boolean
@@ -97,8 +104,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
97104 if ( ! props . current ) return
98105 const key = props . key ( props . current )
99106 requestAnimationFrame ( ( ) => {
100- const element = scroll . querySelector ( `[data- key=" ${ CSS . escape ( key ) } "]` )
101- if ( ! ( element instanceof HTMLElement ) ) return
107+ const element = findByKey ( scroll , key )
108+ if ( ! element ) return
102109 scrollIntoView ( scroll , element , "center" )
103110 } )
104111 } )
@@ -114,8 +121,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
114121 }
115122 const key = active ( )
116123 if ( ! key ) return
117- const element = scroll . querySelector ( `[data- key=" ${ CSS . escape ( key ) } "]` )
118- if ( ! ( element instanceof HTMLElement ) ) return
124+ const element = findByKey ( scroll , key )
125+ if ( ! element ) return
119126 scrollIntoView ( scroll , element , "center" )
120127 } )
121128
0 commit comments