no-access-key.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _jsxAstUtils = require("jsx-ast-utils");
  7. var _schemas = require("../util/schemas");
  8. /**
  9. * @fileoverview Enforce no accesskey attribute on element.
  10. * @author Ethan Cohen
  11. */
  12. // ----------------------------------------------------------------------------
  13. // Rule Definition
  14. // ----------------------------------------------------------------------------
  15. var errorMessage = 'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard commands used by screenreaders and keyboard-only users create a11y complications.';
  16. var schema = (0, _schemas.generateObjSchema)();
  17. var _default = exports["default"] = {
  18. meta: {
  19. docs: {
  20. url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-access-key.md',
  21. description: 'Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screenreader.'
  22. },
  23. schema: [schema]
  24. },
  25. create: function create(context) {
  26. return {
  27. JSXOpeningElement: function JSXOpeningElement(node) {
  28. var accessKey = (0, _jsxAstUtils.getProp)(node.attributes, 'accesskey');
  29. var accessKeyValue = (0, _jsxAstUtils.getPropValue)(accessKey);
  30. if (accessKey && accessKeyValue) {
  31. context.report({
  32. node,
  33. message: errorMessage
  34. });
  35. }
  36. }
  37. };
  38. }
  39. };
  40. module.exports = exports.default;