Skip to content

Commit

Permalink
feat(is-focusable): account for negative tabindex
Browse files Browse the repository at this point in the history
- add option arg that enables looking for negative tabindex (defaults to false)

references: #3500
  • Loading branch information
dbowling committed Aug 16, 2022
1 parent e4de11f commit 124c1a3
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 82 deletions.
11 changes: 10 additions & 1 deletion lib/commons/dom/is-focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { getNodeFromTree } from '../../core/utils';
* @memberof axe.commons.dom
* @instance
* @param {HTMLElement} el The HTMLElement
* @param {object} options Optional. If set to {programatically: false}, the function will return true
* @return {Boolean} The element's focusability status
*/
export default function isFocusable(el) {
export default function isFocusable(el, options = { programmatically: false }) {
const vNode = el instanceof AbstractVirtualNode ? el : getNodeFromTree(el);

if (vNode.props.nodeType !== 1) {
Expand All @@ -23,8 +24,16 @@ export default function isFocusable(el) {
} else if (isNativelyFocusable(vNode)) {
return true;
}

// check if the tabindex is specified and a parseable number
var tabindex = vNode.attr('tabindex');
if (
tabindex &&
options.programmatically === true &&
parseInt(tabindex, 10) === -1
) {
return false;
}
if (tabindex && !isNaN(parseInt(tabindex, 10))) {
return true;
}
Expand Down
Loading

0 comments on commit 124c1a3

Please sign in to comment.