Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-a11y-utils): fix focus region missing mouse down target #1806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/ui-a11y-utils/src/FocusRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class FocusRegion {
private readonly _id: string
private _listeners: ReturnType<typeof addEventListener>[] = []
private _active = false
private _documentClickTarget: Node | null = null
private _contextContainsTarget = false
private _documentMouseDownTarget: Node | null = null

constructor(element: Element | Node | null, options: FocusRegionOptions) {
this._options = options || {
Expand Down Expand Up @@ -83,19 +82,17 @@ class FocusRegion {
}

captureDocumentMousedown = (event: React.MouseEvent) => {
this._documentClickTarget = event.target as Node
this._contextContainsTarget = contains(
this._contextElement,
this._documentClickTarget
)
// FocusRegion can be activated after mousedown but before click so this is not guaranteed to fire.
this._documentMouseDownTarget = event.target as Node
}

handleDocumentClick = (event: React.PointerEvent) => {
if (
this._options.shouldCloseOnDocumentClick &&
event.button === 0 &&
event.detail > 0 && // if event.detail is 0 then this is a keyboard and not a mouse press
!this._contextContainsTarget
this._documentMouseDownTarget !== null &&
!contains(this._contextElement, this._documentMouseDownTarget)
) {
this.handleDismiss(event, true)
}
Expand Down
Loading