Skip to content

Commit

Permalink
Merge pull request #37780 from nextcloud/enh/a11y-focus-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal committed Apr 25, 2023
2 parents 6d9f785 + 79310bd commit 721de34
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
21 changes: 20 additions & 1 deletion core/src/jquery/ocdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

import $ from 'jquery'
import { createFocusTrap } from 'focus-trap'
import { isA11yActivation } from '../Util/a11y.js'

$.widget('oc.ocdialog', {
Expand Down Expand Up @@ -114,9 +115,9 @@ $.widget('oc.ocdialog', {

this._setOptions(this.options)
this._createOverlay()
this._useFocusTrap()
},
_init() {
this.$dialog.focus()
this._trigger('open')
},
_setOption(key, value) {
Expand Down Expand Up @@ -252,6 +253,23 @@ $.widget('oc.ocdialog', {
this.overlay = null
}
},
_useFocusTrap() {
// Create global stack if undefined
Object.assign(window, { _nc_focus_trap: window._nc_focus_trap || [] })

const dialogElement = this.$dialog[0]
this.focusTrap = createFocusTrap(dialogElement, {
allowOutsideClick: true,
trapStack: window._nc_focus_trap,
fallbackFocus: dialogElement,
})

this.focusTrap.activate()
},
_clearFocusTrap() {
this.focusTrap?.deactivate()
this.focusTrap = null
},
widget() {
return this.$dialog
},
Expand All @@ -262,6 +280,7 @@ $.widget('oc.ocdialog', {
this.enterCallback = null
},
close() {
this._clearFocusTrap()
this._destroyOverlay()
const self = this
// Ugly hack to catch remaining keyup events.
Expand Down
4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-main.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"debounce": "^1.2.1",
"dompurify": "^2.3.6",
"escape-html": "^1.0.3",
"focus-trap": "^7.4.0",
"focus-visible": "^5.2.0",
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
Expand Down

0 comments on commit 721de34

Please sign in to comment.