@@ -50,7 +50,8 @@ class FocusRegion {
5050 constructor ( element : Element | Node | null , options : FocusRegionOptions ) {
5151 this . _options = options || {
5252 shouldCloseOnDocumentClick : true ,
53- shouldCloseOnEscape : true
53+ shouldCloseOnEscape : true ,
54+ isTooltip : false
5455 }
5556 this . _contextElement = element
5657 this . _screenReaderFocusRegion = new ScreenReaderFocusRegion (
@@ -122,6 +123,10 @@ class FocusRegion {
122123 if ( fileInputFocused ) {
123124 ; ( < HTMLInputElement > activeElement ) . blur ( )
124125 } else {
126+ //This should prevent a Tooltip from closing when inside of a Modal
127+ if ( this . _options . isTooltip ) {
128+ event . stopPropagation ( )
129+ }
125130 this . handleDismiss ( event )
126131 }
127132 }
@@ -169,9 +174,14 @@ class FocusRegion {
169174 }
170175 } )
171176 }
172-
177+ //This will ensure that the Tooltip's Escape event listener is executed first
178+ //because listeners in the capturing phase are called before other event listeners (like that of the Modal's Escape listener)
179+ //so a Modal with a Tooltip will not get closed when closing the Tooltip with Escape
180+ const useCapture = this . _options . isTooltip
173181 if ( this . _options . shouldCloseOnEscape ) {
174- this . _listeners . push ( addEventListener ( doc , 'keyup' , this . handleKeyUp ) )
182+ this . _listeners . push (
183+ addEventListener ( doc , 'keyup' , this . handleKeyUp , useCapture )
184+ )
175185 }
176186
177187 this . _active = true
0 commit comments