Skip to content

Commit

Permalink
Merge pull request #519 from KittyGiraudel/safari-focus-bug-v8
Browse files Browse the repository at this point in the history
[Version 8] Issue a workaround for a long-lasting Safari focus bug
  • Loading branch information
KittyGiraudel authored Jul 22, 2023
2 parents cfb4595 + 6aafeb9 commit f11ff2a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/a11y-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,20 @@ export default class A11yDialog {

// Keep a reference to the currently focused element to be able to restore
// it later
this.previouslyFocused = getActiveElement() as HTMLElement
this.shown = true
this.$el.removeAttribute('aria-hidden')
this.previouslyFocused = getActiveElement() as HTMLElement

// Due to a long lasting bug in Safari, clicking an interactive element
// (like a <button>) does *not* move the focus to that element, which means
// `document.activeElement` is whatever element is currently focused (like
// an <input>), or the <body> element otherwise. We can work around that
// problem by checking whether the focused element is the <body>, and if it,
// store the click event target.
// See: https://bugs.webkit.org/show_bug.cgi?id=22261
if (this.previouslyFocused?.tagName === 'BODY' && event?.target) {
this.previouslyFocused = event.target as HTMLElement
}

// Set the focus to the dialog element
moveFocusToDialog(this.$el)
Expand Down

0 comments on commit f11ff2a

Please sign in to comment.