Guard against null in aria-menu

pull/19210/head
wenincode 1 year ago
parent 467226959b
commit 0ab9db65d3

@ -53,7 +53,7 @@ export default class AriaMenuModifier extends Modifier {
async keydown(e) { async keydown(e) {
if (e.keyCode === ESC) { if (e.keyCode === ESC) {
this.options.onclose(e); this.options.onclose(e);
this.$trigger.focus(); this.$trigger?.focus();
return; return;
} }
const $items = [...this.element.querySelectorAll(MENU_ITEMS)]; const $items = [...this.element.querySelectorAll(MENU_ITEMS)];
@ -62,7 +62,7 @@ export default class AriaMenuModifier extends Modifier {
if (e.shiftKey) { if (e.shiftKey) {
if (pos === 0) { if (pos === 0) {
this.options.onclose(e); this.options.onclose(e);
this.$trigger.focus(); this.$trigger?.focus();
} }
} else { } else {
if (pos === $items.length - 1) { if (pos === $items.length - 1) {
@ -75,7 +75,7 @@ export default class AriaMenuModifier extends Modifier {
if (typeof keys[this.orientation][e.keyCode] === 'undefined') { if (typeof keys[this.orientation][e.keyCode] === 'undefined') {
return; return;
} }
$items[keys[this.orientation][e.keyCode]($items, pos)].focus(); $items[keys[this.orientation][e.keyCode]($items, pos)]?.focus();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} }

Loading…
Cancel
Save