Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative tabindex is allowed in aria-activedescendant-has-tabindex rule #708

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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