| 1 | /**
|
|---|
| 2 | * @fileoverview Enforce elements with aria-activedescendant are tabbable.
|
|---|
| 3 | * @author Jesse Beach <@jessebeach>
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | // -----------------------------------------------------------------------------
|
|---|
| 7 | // Requirements
|
|---|
| 8 | // -----------------------------------------------------------------------------
|
|---|
| 9 |
|
|---|
| 10 | import { RuleTester } from 'eslint';
|
|---|
| 11 | import parserOptionsMapper from '../../__util__/parserOptionsMapper';
|
|---|
| 12 | import parsers from '../../__util__/helpers/parsers';
|
|---|
| 13 | import rule from '../../../src/rules/aria-activedescendant-has-tabindex';
|
|---|
| 14 |
|
|---|
| 15 | // -----------------------------------------------------------------------------
|
|---|
| 16 | // Tests
|
|---|
| 17 | // -----------------------------------------------------------------------------
|
|---|
| 18 |
|
|---|
| 19 | const ruleTester = new RuleTester();
|
|---|
| 20 |
|
|---|
| 21 | const expectedError = {
|
|---|
| 22 | message: 'An element that manages focus with `aria-activedescendant` must have a tabindex',
|
|---|
| 23 | type: 'JSXOpeningElement',
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | ruleTester.run('aria-activedescendant-has-tabindex', rule, {
|
|---|
| 27 | valid: parsers.all([].concat(
|
|---|
| 28 | {
|
|---|
| 29 | code: '<CustomComponent />;',
|
|---|
| 30 | },
|
|---|
| 31 | {
|
|---|
| 32 | code: '<CustomComponent aria-activedescendant={someID} />;',
|
|---|
| 33 | },
|
|---|
| 34 | {
|
|---|
| 35 | code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;',
|
|---|
| 36 | },
|
|---|
| 37 | {
|
|---|
| 38 | code: '<CustomComponent aria-activedescendant={someID} tabIndex={-1} />;',
|
|---|
| 39 | },
|
|---|
| 40 | {
|
|---|
| 41 | code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;',
|
|---|
| 42 | settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } },
|
|---|
| 43 | },
|
|---|
| 44 | {
|
|---|
| 45 | code: '<div />;',
|
|---|
| 46 | },
|
|---|
| 47 | {
|
|---|
| 48 | code: '<input />;',
|
|---|
| 49 | },
|
|---|
| 50 | {
|
|---|
| 51 | code: '<div tabIndex={0} />;',
|
|---|
| 52 | },
|
|---|
| 53 | {
|
|---|
| 54 | code: '<div aria-activedescendant={someID} tabIndex={0} />;',
|
|---|
| 55 | },
|
|---|
| 56 | {
|
|---|
| 57 | code: '<div aria-activedescendant={someID} tabIndex="0" />;',
|
|---|
| 58 | },
|
|---|
| 59 | {
|
|---|
| 60 | code: '<div aria-activedescendant={someID} tabIndex={1} />;',
|
|---|
| 61 | },
|
|---|
| 62 | {
|
|---|
| 63 | code: '<input aria-activedescendant={someID} />;',
|
|---|
| 64 | },
|
|---|
| 65 | {
|
|---|
| 66 | code: '<input aria-activedescendant={someID} tabIndex={1} />;',
|
|---|
| 67 | },
|
|---|
| 68 | {
|
|---|
| 69 | code: '<input aria-activedescendant={someID} tabIndex={0} />;',
|
|---|
| 70 | },
|
|---|
| 71 | {
|
|---|
| 72 | code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
|
|---|
| 73 | },
|
|---|
| 74 | {
|
|---|
| 75 | code: '<div aria-activedescendant={someID} tabIndex={-1} />;',
|
|---|
| 76 | },
|
|---|
| 77 | {
|
|---|
| 78 | code: '<div aria-activedescendant={someID} tabIndex="-1" />;',
|
|---|
| 79 | },
|
|---|
| 80 | {
|
|---|
| 81 | code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
|
|---|
| 82 | },
|
|---|
| 83 | )).map(parserOptionsMapper),
|
|---|
| 84 | invalid: parsers.all([].concat(
|
|---|
| 85 | {
|
|---|
| 86 | code: '<div aria-activedescendant={someID} />;',
|
|---|
| 87 | errors: [expectedError],
|
|---|
| 88 | },
|
|---|
| 89 | {
|
|---|
| 90 | code: '<CustomComponent aria-activedescendant={someID} />;',
|
|---|
| 91 | errors: [expectedError],
|
|---|
| 92 | settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } },
|
|---|
| 93 | },
|
|---|
| 94 | )).map(parserOptionsMapper),
|
|---|
| 95 | });
|
|---|