@@ -503,6 +503,47 @@ describe('Select', () => {
503503 expect ( trigger ) . toHaveTextContent ( 'Northern Territory' ) ;
504504 expect ( trigger ) . not . toHaveAttribute ( 'data-pressed' ) ;
505505 } ) ;
506+
507+ it ( 'should handle typeahead transitions correctly with and without debounce' , async ( ) => {
508+ let { getByTestId} = render (
509+ < Select data-testid = "select" >
510+ < Label > Test</ Label >
511+ < Button >
512+ < SelectValue />
513+ </ Button >
514+ < Popover >
515+ < ListBox >
516+ < ListBoxItem id = "a" > a</ ListBoxItem >
517+ < ListBoxItem id = "aa" > aa</ ListBoxItem >
518+ < ListBoxItem id = "ab" > ab</ ListBoxItem >
519+ </ ListBox >
520+ </ Popover >
521+ </ Select >
522+ ) ;
523+
524+ let wrapper = getByTestId ( 'select' ) ;
525+ let selectTester = testUtilUser . createTester ( 'Select' , { root : wrapper } ) ;
526+ let trigger = selectTester . trigger ;
527+
528+ await user . tab ( ) ;
529+
530+ await user . keyboard ( 'a' ) ;
531+ expect ( trigger ) . toHaveTextContent ( 'a' ) ;
532+
533+ // continuing search narrows — 'aa' matches 'aa'
534+ await user . keyboard ( 'a' ) ;
535+ expect ( trigger ) . toHaveTextContent ( 'aa' ) ;
536+
537+ // no match on 'aaa' — selection unchanged
538+ await user . keyboard ( 'a' ) ;
539+ expect ( trigger ) . toHaveTextContent ( 'aa' ) ;
540+
541+ act ( ( ) => { jest . runAllTimers ( ) ; } ) ;
542+
543+ // new search after debounce skips focused item and cycles to next match
544+ await user . keyboard ( 'a' ) ;
545+ expect ( trigger ) . toHaveTextContent ( 'ab' ) ;
546+ } ) ;
506547 } ) ;
507548
508549 it ( 'should support autoFocus' , ( ) => {
0 commit comments