Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

79 lignes
3.1 KiB

  1. 'use strict';
  2. var _ariaQuery = require('aria-query');
  3. var _jsxAstUtils = require('jsx-ast-utils');
  4. var _schemas = require('../util/schemas');
  5. var _getTabIndex = require('../util/getTabIndex');
  6. var _getTabIndex2 = _interopRequireDefault(_getTabIndex);
  7. var _isInteractiveElement = require('../util/isInteractiveElement');
  8. var _isInteractiveElement2 = _interopRequireDefault(_isInteractiveElement);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /**
  11. * @fileoverview Enforce elements with aria-activedescendant are tabbable.
  12. * @author Jesse Beach <@jessebeach>
  13. */
  14. // ----------------------------------------------------------------------------
  15. // Rule Definition
  16. // ----------------------------------------------------------------------------
  17. var errorMessage = 'An element that manages focus with `aria-activedescendant` must be tabbable';
  18. var schema = (0, _schemas.generateObjSchema)();
  19. var domElements = [].concat(_toConsumableArray(_ariaQuery.dom.keys()));
  20. module.exports = {
  21. meta: {
  22. docs: {
  23. url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/aria-activedescendant-has-tabindex.md'
  24. },
  25. schema: [schema]
  26. },
  27. create: function create(context) {
  28. return {
  29. JSXOpeningElement: function JSXOpeningElement(node) {
  30. var attributes = node.attributes;
  31. if ((0, _jsxAstUtils.getProp)(attributes, 'aria-activedescendant') === undefined) {
  32. return;
  33. }
  34. var type = (0, _jsxAstUtils.elementType)(node);
  35. // Do not test higher level JSX components, as we do not know what
  36. // low-level DOM element this maps to.
  37. if (domElements.indexOf(type) === -1) {
  38. return;
  39. }
  40. var tabIndex = (0, _getTabIndex2.default)((0, _jsxAstUtils.getProp)(attributes, 'tabIndex'));
  41. // If this is an interactive element, tabIndex must be either left
  42. // unspecified allowing the inherent tabIndex to obtain or it must be
  43. // zero (allowing for positive, even though that is not ideal). It cannot
  44. // be given a negative value.
  45. if ((0, _isInteractiveElement2.default)(type, attributes) && (tabIndex === undefined || tabIndex >= 0)) {
  46. return;
  47. }
  48. if (tabIndex >= 0) {
  49. return;
  50. }
  51. context.report({
  52. node: node,
  53. message: errorMessage
  54. });
  55. }
  56. };
  57. }
  58. };