diff --git a/lib/commons/dom/focus-disabled.js b/lib/commons/dom/focus-disabled.js index e1288f1be8..108ec7b301 100644 --- a/lib/commons/dom/focus-disabled.js +++ b/lib/commons/dom/focus-disabled.js @@ -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. @@ -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; } diff --git a/test/checks/keyboard/no-focusable-content.js b/test/checks/keyboard/no-focusable-content.js index d642bbd15e..e10b4679b0 100644 --- a/test/checks/keyboard/no-focusable-content.js +++ b/test/checks/keyboard/no-focusable-content.js @@ -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( + '' + ); + 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(' some text ' +'JavaScript is able to focus this '