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 popover reopen when clicking the trigger #1348

Merged
merged 1 commit into from
Nov 3, 2023
Merged
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
16 changes: 4 additions & 12 deletions packages/ui-a11y-utils/src/FocusRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { FocusRegionOptions } from './FocusRegionOptions'

class FocusRegion {
private _contextElement: Node | Element | null = null
private _preventCloseOnDocumentClick = false
private _options: FocusRegionOptions
private readonly _screenReaderFocusRegion: ScreenReaderFocusRegion
private readonly _keyboardFocusRegion: KeyboardFocusRegion
Expand Down Expand Up @@ -81,16 +80,12 @@ class FocusRegion {
this._options.onDismiss?.(event, documentClick)
}

captureDocumentClick = (event: React.MouseEvent) => {
const { target } = event
this._preventCloseOnDocumentClick =
event.button !== 0 || contains(this._contextElement, target as Node)
}

handleDocumentClick = (event: React.MouseEvent) => {
const { target } = event
if (
this._options.shouldCloseOnDocumentClick &&
!this._preventCloseOnDocumentClick
event.button == 0 &&
!contains(this._contextElement, target as Node)
) {
this.handleDismiss(event, true)
}
Expand Down Expand Up @@ -148,10 +143,7 @@ class FocusRegion {

if (this._options.shouldCloseOnDocumentClick) {
this._listeners.push(
addEventListener(doc, 'mousedown', this.captureDocumentClick, true)
)
this._listeners.push(
addEventListener(doc, 'mouseup', this.handleDocumentClick)
addEventListener(doc, 'click', this.handleDocumentClick)
)

Array.from(doc.getElementsByTagName('iframe')).forEach((el) => {
Expand Down
Loading