@@ -385,6 +385,58 @@ describe('<Autocomplete.Root />', () => {
385385 expect ( input ) . to . have . attribute ( 'aria-activedescendant' , firstOption . id ) ;
386386 expect ( firstOption ) . to . have . attribute ( 'data-highlighted' ) ;
387387 } ) ;
388+
389+ it ( 'keeps the latest pointer highlight on outside blur when behavior is "always"' , async ( ) => {
390+ const { user } = await render (
391+ < React . Fragment >
392+ < Autocomplete . Root
393+ items = { [ 'apple' , 'banana' , 'cherry' ] }
394+ autoHighlight = "always"
395+ keepHighlight
396+ open
397+ inline
398+ >
399+ < Autocomplete . Input data-testid = "input" />
400+ < Autocomplete . List >
401+ { ( item : string ) => (
402+ < Autocomplete . Item key = { item } value = { item } >
403+ { item }
404+ </ Autocomplete . Item >
405+ ) }
406+ </ Autocomplete . List >
407+ </ Autocomplete . Root >
408+ < button data-testid = "outside" > outside</ button >
409+ </ React . Fragment > ,
410+ ) ;
411+
412+ const input = screen . getByTestId < HTMLInputElement > ( 'input' ) ;
413+ const banana = screen . getByRole ( 'option' , { name : 'banana' } ) ;
414+
415+ await act ( async ( ) => {
416+ input . focus ( ) ;
417+ } ) ;
418+
419+ await user . hover ( banana ) ;
420+
421+ await waitFor ( ( ) => {
422+ expect ( input ) . to . have . attribute ( 'aria-activedescendant' , banana . id ) ;
423+ expect ( banana ) . to . have . attribute ( 'data-highlighted' ) ;
424+ } ) ;
425+
426+ const outside = screen . getByTestId ( 'outside' ) ;
427+ fireEvent . pointerDown ( outside ) ;
428+ fireEvent . blur ( input , { relatedTarget : outside } ) ;
429+ fireEvent . focus ( outside ) ;
430+
431+ await waitFor ( ( ) => {
432+ expect ( input ) . to . have . attribute ( 'aria-activedescendant' , banana . id ) ;
433+ expect ( banana ) . to . have . attribute ( 'data-highlighted' ) ;
434+ } ) ;
435+
436+ expect ( screen . getByRole ( 'option' , { name : 'apple' } ) ) . not . to . have . attribute (
437+ 'data-highlighted' ,
438+ ) ;
439+ } ) ;
388440 } ) ;
389441
390442 describe ( 'prop: keepHighlight' , ( ) => {
0 commit comments