@@ -17,6 +17,7 @@ import {
1717 ComboboxPopover ,
1818 useComboboxContext ,
1919} from "@reach/combobox" ;
20+ import { Dialog } from "@reach/dialog" ;
2021import { matchSorter } from "match-sorter" ;
2122import cities from "./cities" ;
2223import { afterEach , describe , expect , it } from "vitest" ;
@@ -251,6 +252,22 @@ describe("<Combobox />", () => {
251252 // expect(queryByRole("listbox")).toBeFalsy();
252253 // });
253254 } ) ;
255+
256+ describe ( "Combobox inside dialog" , ( ) => {
257+ it ( "should not close the dialog when Esc key is pressed" , ( ) => {
258+ let { getByRole, queryByRole } = render ( < BasicComboboxInDialog /> ) ;
259+ let input = getByRole ( "combobox" ) ;
260+
261+ expect ( getByRole ( "dialog" ) ) . toBeInTheDocument ( ) ;
262+
263+ userEvent . type ( input , "e" ) ;
264+ expect ( getByRole ( "listbox" ) ) . toBeInTheDocument ( ) ;
265+
266+ userEvent . keyboard ( "{esc}" ) ;
267+ expect ( queryByRole ( "listbox" ) ) . not . toBeInTheDocument ( ) ;
268+ expect ( queryByRole ( "dialog" ) ) . toBeInTheDocument ( ) ;
269+ } ) ;
270+ } ) ;
254271} ) ;
255272
256273////////////////////////////////////////////////////////////////////////////////
@@ -343,6 +360,20 @@ function BasicCombobox() {
343360// );
344361// }
345362
363+ function BasicComboboxInDialog ( ) {
364+ const [ showDialog , setShowDialog ] = React . useState ( true ) ;
365+
366+ return (
367+ < Dialog
368+ isOpen = { showDialog }
369+ onDismiss = { ( ) => setShowDialog ( false ) }
370+ aria-label = "dialog with combobox"
371+ >
372+ < BasicCombobox />
373+ </ Dialog >
374+ ) ;
375+ }
376+
346377function useCityMatch ( term : string ) {
347378 return term . trim ( ) === ""
348379 ? null
0 commit comments