Skip to content

Commit bb8b5ca

Browse files
dan-trippstraker
andauthored
fix(checks/no-focusable-disable): don't count non-disableable elements as disabled (dequelabs#3393)
* refactor(checks/navigation): improve `internal-link-present-evaluate` Make `internal-link-present-evaluate` work with virtualNode rather than actualNode. Closes issue dequelabs#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 dequelabs#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 dequelabs#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 dequelabs#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>
1 parent fa6cbf4 commit bb8b5ca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/commons/dom/focus-disabled.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node';
22
import { getNodeFromTree } from '../../core/utils';
33
import isHiddenWithCSS from './is-hidden-with-css';
4+
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
5+
const allowedDisabledNodeNames = [
6+
'button',
7+
'command',
8+
'fieldset',
9+
'keygen',
10+
'optgroup',
11+
'option',
12+
'select',
13+
'textarea',
14+
'input'
15+
];
16+
17+
function isDisabledAttrAllowed(nodeName) {
18+
return allowedDisabledNodeNames.includes(nodeName);
19+
}
420

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

13-
if (vNode.hasAttr('disabled')) {
29+
if (isDisabledAttrAllowed(vNode.props.nodeName) && vNode.hasAttr('disabled')) {
1430
return true;
1531
}
1632

test/checks/keyboard/no-focusable-content.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ describe('no-focusable-content tests', function() {
9393
assert.isTrue(noFocusableContent(null, null, vNode));
9494
});
9595

96+
it('should return false if "disabled" is specified on an element which doesn\'t allow it', function() {
97+
var params = checkSetup(
98+
'<button id="target"><a href="foo.html" disabled>Hello</a></button>'
99+
);
100+
assert.isFalse(noFocusableContent.apply(checkContext, params));
101+
});
102+
96103
it('should return true on span with negative tabindex (focusable, does not have a widget role)', function() {
97104
var vNode = queryFixture('<span id="target" role="text"> some text '
98105
+'<span tabIndex="-1">JavaScript is able to focus this</span> '

0 commit comments

Comments
 (0)