@@ -45,8 +45,7 @@ class FocusRegion {
4545 private readonly _id : string
4646 private _listeners : ReturnType < typeof addEventListener > [ ] = [ ]
4747 private _active = false
48- private _documentClickTarget : Node | null = null
49- private _contextContainsTarget = false
48+ private _documentMouseDownTarget : Node | null = null
5049
5150 constructor ( element : Element | Node | null , options : FocusRegionOptions ) {
5251 this . _options = options || {
@@ -83,19 +82,17 @@ class FocusRegion {
8382 }
8483
8584 captureDocumentMousedown = ( event : React . MouseEvent ) => {
86- this . _documentClickTarget = event . target as Node
87- this . _contextContainsTarget = contains (
88- this . _contextElement ,
89- this . _documentClickTarget
90- )
85+ // FocusRegion can be activated after mousedown but before click so this is not guaranteed to fire.
86+ this . _documentMouseDownTarget = event . target as Node
9187 }
9288
9389 handleDocumentClick = ( event : React . PointerEvent ) => {
9490 if (
9591 this . _options . shouldCloseOnDocumentClick &&
9692 event . button === 0 &&
9793 event . detail > 0 && // if event.detail is 0 then this is a keyboard and not a mouse press
98- ! this . _contextContainsTarget
94+ this . _documentMouseDownTarget !== null &&
95+ ! contains ( this . _contextElement , this . _documentMouseDownTarget )
9996 ) {
10097 this . handleDismiss ( event , true )
10198 }
0 commit comments