| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _ariaQuery = require("aria-query");
|
|---|
| 8 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 9 | var _schemas = require("../util/schemas");
|
|---|
| 10 | var _getElementType = _interopRequireDefault(require("../util/getElementType"));
|
|---|
| 11 | var _getTabIndex = _interopRequireDefault(require("../util/getTabIndex"));
|
|---|
| 12 | var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
|
|---|
| 13 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|---|
| 14 | /**
|
|---|
| 15 | * @fileoverview Enforce elements with aria-activedescendant are tabbable.
|
|---|
| 16 | * @author Jesse Beach <@jessebeach>
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | // ----------------------------------------------------------------------------
|
|---|
| 20 | // Rule Definition
|
|---|
| 21 | // ----------------------------------------------------------------------------
|
|---|
| 22 |
|
|---|
| 23 | var errorMessage = 'An element that manages focus with `aria-activedescendant` must have a tabindex';
|
|---|
| 24 | var schema = (0, _schemas.generateObjSchema)();
|
|---|
| 25 | var _default = exports["default"] = {
|
|---|
| 26 | meta: {
|
|---|
| 27 | docs: {
|
|---|
| 28 | url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-activedescendant-has-tabindex.md',
|
|---|
| 29 | description: 'Enforce elements with aria-activedescendant are tabbable.'
|
|---|
| 30 | },
|
|---|
| 31 | schema: [schema]
|
|---|
| 32 | },
|
|---|
| 33 | create: function create(context) {
|
|---|
| 34 | var elementType = (0, _getElementType["default"])(context);
|
|---|
| 35 | return {
|
|---|
| 36 | JSXOpeningElement: function JSXOpeningElement(node) {
|
|---|
| 37 | var attributes = node.attributes;
|
|---|
| 38 | if ((0, _jsxAstUtils.getProp)(attributes, 'aria-activedescendant') === undefined) {
|
|---|
| 39 | return;
|
|---|
| 40 | }
|
|---|
| 41 | var type = elementType(node);
|
|---|
| 42 | // Do not test higher level JSX components, as we do not know what
|
|---|
| 43 | // low-level DOM element this maps to.
|
|---|
| 44 | if (!_ariaQuery.dom.has(type)) {
|
|---|
| 45 | return;
|
|---|
| 46 | }
|
|---|
| 47 | var tabIndex = (0, _getTabIndex["default"])((0, _jsxAstUtils.getProp)(attributes, 'tabIndex'));
|
|---|
| 48 |
|
|---|
| 49 | // If this is an interactive element and the tabindex attribute is not specified,
|
|---|
| 50 | // or the tabIndex property was not mutated, then the tabIndex
|
|---|
| 51 | // property will be undefined.
|
|---|
| 52 | if ((0, _isInteractiveElement["default"])(type, attributes) && tabIndex === undefined) {
|
|---|
| 53 | return;
|
|---|
| 54 | }
|
|---|
| 55 | if (tabIndex >= -1) {
|
|---|
| 56 | return;
|
|---|
| 57 | }
|
|---|
| 58 | context.report({
|
|---|
| 59 | node,
|
|---|
| 60 | message: errorMessage
|
|---|
| 61 | });
|
|---|
| 62 | }
|
|---|
| 63 | };
|
|---|
| 64 | }
|
|---|
| 65 | };
|
|---|
| 66 | module.exports = exports.default; |
|---|