Skip to content

Commit

Permalink
fix(ui-a11y-utils): fix parent dialog closing when file picker input …
Browse files Browse the repository at this point in the history
…is closed

Closes: INSTUI-3804
  • Loading branch information
balzss committed Jul 21, 2023
1 parent eefd8ce commit 1732297
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/ui-a11y-utils/src/FocusRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ class FocusRegion {
event.keyCode === keycode.codes.esc &&
!event.defaultPrevented
) {
this.handleDismiss(event)
// If a dialog contains an <input type="file"/> element and the user opens the file picker and closes it with the
// escape key then Firefox passes through that event which could close the parent dialog. This code prevents that
// from happening (listening for a `cancel` event doesn't seem to work in firefox)
const activeElement = ownerDocument(this._contextElement).activeElement
const fileInputFocused =
activeElement?.tagName === 'INPUT' &&
(<HTMLInputElement>activeElement).type === 'file'

if (fileInputFocused) {
;(<HTMLInputElement>activeElement).blur()
} else {
this.handleDismiss(event)
}
}
}

Expand Down

0 comments on commit 1732297

Please sign in to comment.