Skip to content

Commit

Permalink
disables shortcut key for skipto when focus is on a text input
Browse files Browse the repository at this point in the history
  • Loading branch information
jongund committed Apr 3, 2024
1 parent f83f4dd commit b5f2b0c
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions content/shared/js/skipto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ========================================================================
* Version: 5.3.0
* Version: 5.3.1
* Copyright (c) 2022, 2023, 2024 Jon Gunderson; Licensed BSD
* Copyright (c) 2021 PayPal Accessibility Team and University of Illinois; Licensed BSD
* All rights reserved.
Expand Down Expand Up @@ -2437,34 +2437,51 @@ $skipToId [role="menuitem"]:focus .label {
}

handleDocumentKeydown (event) {
let key = event.key,
flag = false;

let altPressed =
this.usesAltKey &&
event.altKey &&
!event.ctrlKey &&
!event.shiftKey &&
!event.metaKey;

let optionPressed =
this.usesOptionKey &&
event.altKey &&
!event.ctrlKey &&
!event.shiftKey &&
!event.metaKey;

if ((optionPressed && this.config.optionShortcut === key) ||
(altPressed && this.config.altShortcut === key) ||
(optionPressed && (48 === event.keyCode))
) {
this.openPopup();
this.setFocusToFirstMenuitem();
flag = true;
}
if (flag) {
event.stopPropagation();
event.preventDefault();
const enabledInputTypes = [
'button',
'checkbox',
'color',
'file',
'image',
'radio',
'range',
'reset',
'submit'
];

const target = event.target;
const tagName = target.tagName ? target.tagName.toLowerCase() : '';
const type = tagName === 'input' ? target.type.toLowerCase() : '';

if ((tagName !== 'textarea') &&
((tagName !== 'input') ||
((tagName === 'input') && enabledInputTypes.includes(type))
)) {

const altPressed =
this.usesAltKey &&
event.altKey &&
!event.ctrlKey &&
!event.shiftKey &&
!event.metaKey;

const optionPressed =
this.usesOptionKey &&
event.altKey &&
!event.ctrlKey &&
!event.shiftKey &&
!event.metaKey;

if ((optionPressed && this.config.optionShortcut === event.key) ||
(altPressed && this.config.altShortcut === event.key) ||
((optionPressed || altPressed) && (48 === event.keyCode))
) {
this.openPopup();
this.setFocusToFirstMenuitem();
event.stopPropagation();
event.preventDefault();
}
}
}

Expand Down

0 comments on commit b5f2b0c

Please sign in to comment.