KittyGiraudel/a11y-dialog

Use `KeyboardEvent.key` instead of `UIEvent.which`?

chalkygames123 opened this issue · 2 comments

Just curious, while the current implementation uses the deprecated which property, is there any reason for this?

a11y-dialog/a11y-dialog.js

Lines 236 to 258 in 142e3b7

A11yDialog.prototype._bindKeypress = function (event) {
// This is an escape hatch in case there are nested dialogs, so the keypresses
// are only reacted to for the most recent one
if (!this.$el.contains(document.activeElement)) return
// If the dialog is shown and the ESCAPE key is being pressed, prevent any
// further effects from the ESCAPE key and hide the dialog, unless its role
// is 'alertdialog', which should be modal
if (
this.shown &&
event.which === ESCAPE_KEY &&
this.$el.getAttribute('role') !== 'alertdialog'
) {
event.preventDefault()
this.hide(event)
}
// If the dialog is shown and the TAB key is being pressed, make sure the
// focus stays trapped within the dialog element
if (this.shown && event.which === TAB_KEY) {
trapTabKey(this.$el, event)
}
}

Though I haven't seen any problems with the current implementation in practice, I thought it would be preferable to follow the standard.

See:

Pretty sure there is no valid reason. I’d happily accept a PR if you feel like submitting one. :)

Okay, I'll try to make a PR when I have some time!