Skip to content

Commit

Permalink
fix(checks/no-focusable-disable): don't count non-disableable element…
Browse files Browse the repository at this point in the history
…s as disabled (#3393)

* refactor(checks/navigation): improve `internal-link-present-evaluate`

Make `internal-link-present-evaluate` work with virtualNode rather than actualNode.

Closes issue #2466

* test commit 1

* test commit 2

* test commit 3

* Revert "Merge branch 'dan-test-branch-1' into develop"

This reverts commit 428e015, reversing
changes made to 9f996bc.

* Revert "test commit 1"

This reverts commit 9f996bc.

* fix(rule): allow "tabindex=-1" for rules "aria-text" and "nested-interactive"

Closes issue #2934

* work in progress

* work in progress

* test commit 1

* Revert "test commit 1"

This reverts commit 9f996bc.

* fix(rule): allow "tabindex=-1" for rules "aria-text" and "nested-interactive"

Closes issue #2934

* work in progress

* work in progress

* fix whitespace

* add new case to test test/checks/keyboard/no-focusable-content.js

* change "disabled" test case in test/checks/keyboard/no-focusable-content.js

* fix merge problem

* fix(commons/dom): focusDisabled() behavior

Now checks "disabled" attribute

Closes issue #3315

* Update lib/commons/dom/focus-disabled.js

Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>

* fix typo

Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
  • Loading branch information
dan-tripp and straker authored Feb 22, 2022
1 parent fa6cbf4 commit bb8b5ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/commons/dom/focus-disabled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node';
import { getNodeFromTree } from '../../core/utils';
import isHiddenWithCSS from './is-hidden-with-css';
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
const allowedDisabledNodeNames = [
'button',
'command',
'fieldset',
'keygen',
'optgroup',
'option',
'select',
'textarea',
'input'
];

function isDisabledAttrAllowed(nodeName) {
return allowedDisabledNodeNames.includes(nodeName);
}

/**
* Determines if focusing has been disabled on an element.
Expand All @@ -10,7 +26,7 @@ import isHiddenWithCSS from './is-hidden-with-css';
function focusDisabled(el) {
const vNode = el instanceof AbstractVirtualNode ? el : getNodeFromTree(el);

if (vNode.hasAttr('disabled')) {
if (isDisabledAttrAllowed(vNode.props.nodeName) && vNode.hasAttr('disabled')) {
return true;
}

Expand Down
7 changes: 7 additions & 0 deletions test/checks/keyboard/no-focusable-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ describe('no-focusable-content tests', function() {
assert.isTrue(noFocusableContent(null, null, vNode));
});

it('should return false if "disabled" is specified on an element which doesn\'t allow it', function() {
var params = checkSetup(
'<button id="target"><a href="foo.html" disabled>Hello</a></button>'
);
assert.isFalse(noFocusableContent.apply(checkContext, params));
});

it('should return true on span with negative tabindex (focusable, does not have a widget role)', function() {
var vNode = queryFixture('<span id="target" role="text"> some text '
+'<span tabIndex="-1">JavaScript is able to focus this</span> '
Expand Down

0 comments on commit bb8b5ca

Please sign in to comment.