Merge pull request #37780 from nextcloud/enh/a11y-focus-dialog

This commit is contained in:
Pytal 2023-04-24 17:05:42 -07:00 committed by GitHub
commit 721de348ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 4 deletions

View file

@ -24,6 +24,7 @@
*/
import $ from 'jquery'
import { createFocusTrap } from 'focus-trap'
import { isA11yActivation } from '../Util/a11y.js'
$.widget('oc.ocdialog', {
@ -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) {
@ -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
},
@ -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.

4
dist/core-main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
package-lock.json generated
View file

@ -44,6 +44,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",

View file

@ -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",