@@ -3,6 +3,7 @@ import { act, render, screen } from '@testing-library/react';
33import { useState } from 'react' ;
44
55import { Button } from '../' ;
6+ import { Dialog } from '../dialog' ;
67import { Popover } from './' ;
78
89const CompControlled = ( ) => {
@@ -69,7 +70,7 @@ describe('Popover', () => {
6970 expect ( screen . getByText ( contentText ) ) . toBeVisible ( ) ;
7071 } ) ;
7172
72- it ( 'should close when we click the button twitce ' , async ( ) => {
73+ it ( 'should close when we click the button twice ' , async ( ) => {
7374 render ( defaultPopover ) ;
7475 const popoverTrigger = screen . getByRole ( 'button' ) ;
7576
@@ -104,6 +105,49 @@ describe('Popover', () => {
104105 expect ( screen . getByText ( contentText ) ) . not . toBeVisible ( ) ;
105106 } ) ;
106107
108+ it ( 'should not close on ESC when a Dialog is open above the popover' , async ( ) => {
109+ const onClose = vi . fn ( ) ;
110+ render (
111+ < >
112+ < Button popovertarget = 'popover' > popover trigger</ Button >
113+ < Popover id = 'popover' onClose = { onClose } >
114+ { contentText }
115+ < Button command = 'show-modal' commandfor = 'dialog' >
116+ dialog trigger
117+ </ Button >
118+ </ Popover >
119+ < Dialog
120+ id = 'dialog'
121+ closeButton = { false }
122+ style = { { inset : 0 , width : '100vw' , height : '100vh' , margin : 0 } }
123+ aria-label = 'covering dialog'
124+ >
125+ dialog content
126+ </ Dialog >
127+ </ > ,
128+ ) ;
129+
130+ const popoverTrigger = screen . getByRole ( 'button' ) ;
131+ await act ( async ( ) => popoverTrigger . click ( ) ) ;
132+
133+ const dialogTrigger = screen . getByRole ( 'button' , {
134+ name : 'dialog trigger' ,
135+ } ) ;
136+ await act ( async ( ) => dialogTrigger . click ( ) ) ;
137+
138+ expect ( screen . getByText ( contentText ) ) . toBeVisible ( ) ;
139+ expect ( screen . getByRole ( 'dialog' ) ) . toBeVisible ( ) ;
140+
141+ const esc = new KeyboardEvent ( 'keydown' , { key : 'Escape' , bubbles : true } ) ;
142+ await act ( async ( ) => document . body . dispatchEvent ( esc ) ) ;
143+
144+ expect ( onClose ) . not . toHaveBeenCalled ( ) ;
145+ expect ( screen . getByText ( contentText ) ) . toBeVisible ( ) ;
146+
147+ expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
148+ expect ( screen . getByText ( 'dialog content' ) ) . not . toBeVisible ( ) ;
149+ } ) ;
150+
107151 it ( 'should close when we press SPACE' , async ( ) => {
108152 render ( defaultPopover ) ;
109153
0 commit comments