Skip to content

Commit

Permalink
Merge pull request #708 from jsx-eslint/673-fix
Browse files Browse the repository at this point in the history
Negative tabindex is allowed in aria-activedescendant-has-tabindex rule
  • Loading branch information
jessebeach authored Jun 22, 2020
2 parents 85801bd + b315698 commit d4dfccb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 10 additions & 7 deletions __tests__/src/rules/aria-activedescendant-has-tabindex-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import rule from '../../../src/rules/aria-activedescendant-has-tabindex';
const ruleTester = new RuleTester();

const expectedError = {
message: 'An element that manages focus with `aria-activedescendant` must be tabbable',
message: 'An element that manages focus with `aria-activedescendant` must have a tabindex',
type: 'JSXOpeningElement',
};

Expand Down Expand Up @@ -57,25 +57,28 @@ ruleTester.run('aria-activedescendant-has-tabindex', rule, {
{
code: '<input aria-activedescendant={someID} />;',
},
{
code: '<input aria-activedescendant={someID} tabIndex={1} />;',
},
{
code: '<input aria-activedescendant={someID} tabIndex={0} />;',
},
].map(parserOptionsMapper),
invalid: [
{
code: '<div aria-activedescendant={someID} />;',
errors: [expectedError],
code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
},
{
code: '<div aria-activedescendant={someID} tabIndex={-1} />;',
errors: [expectedError],
},
{
code: '<div aria-activedescendant={someID} tabIndex="-1" />;',
errors: [expectedError],
},
{
code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
},
].map(parserOptionsMapper),
invalid: [
{
code: '<div aria-activedescendant={someID} />;',
errors: [expectedError],
},
].map(parserOptionsMapper),
Expand Down
16 changes: 6 additions & 10 deletions src/rules/aria-activedescendant-has-tabindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import isInteractiveElement from '../util/isInteractiveElement';
// Rule Definition
// ----------------------------------------------------------------------------

const errorMessage = 'An element that manages focus with `aria-activedescendant` must be tabbable';
const errorMessage = 'An element that manages focus with `aria-activedescendant` must have a tabindex';

const schema = generateObjSchema();

Expand Down Expand Up @@ -43,21 +43,17 @@ module.exports = {
}
const tabIndex = getTabIndex(getProp(attributes, 'tabIndex'));

// If this is an interactive element, tabIndex must be either left
// unspecified allowing the inherent tabIndex to obtain or it must be
// zero (allowing for positive, even though that is not ideal). It cannot
// be given a negative value.
// If this is an interactive element and the tabindex attribute is not specified,
// or the tabIndex property was not mutated, then the tabIndex
// property will be undefined.
if (
isInteractiveElement(type, attributes)
&& (
tabIndex === undefined
|| tabIndex >= 0
)
&& tabIndex === undefined
) {
return;
}

if (tabIndex >= 0) {
if (tabIndex >= -1) {
return;
}

Expand Down

0 comments on commit d4dfccb

Please sign in to comment.