source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/rules/no-static-element-interactions.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 5.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _ariaQuery = require("aria-query");
8var _jsxAstUtils = require("jsx-ast-utils");
9var _schemas = require("../util/schemas");
10var _getElementType = _interopRequireDefault(require("../util/getElementType"));
11var _isAbstractRole = _interopRequireDefault(require("../util/isAbstractRole"));
12var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
13var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
14var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
15var _isNonInteractiveElement = _interopRequireDefault(require("../util/isNonInteractiveElement"));
16var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
17var _isNonLiteralProperty = _interopRequireDefault(require("../util/isNonLiteralProperty"));
18var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
19function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
20/**
21 * @fileoverview Enforce static elements have no interactive handlers.
22 * @author Ethan Cohen
23 *
24 */
25
26// ----------------------------------------------------------------------------
27// Rule Definition
28// ----------------------------------------------------------------------------
29
30var errorMessage = 'Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element.';
31var defaultInteractiveProps = [].concat(_jsxAstUtils.eventHandlersByType.focus, _jsxAstUtils.eventHandlersByType.keyboard, _jsxAstUtils.eventHandlersByType.mouse);
32var schema = (0, _schemas.generateObjSchema)({
33 handlers: _schemas.arraySchema
34});
35var _default = exports["default"] = {
36 meta: {
37 docs: {
38 url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-static-element-interactions.md',
39 description: 'Enforce that non-interactive, visible elements (such as `<div>`) that have click handlers use the role attribute.'
40 },
41 schema: [schema]
42 },
43 create: function create(context) {
44 var options = context.options;
45 var elementType = (0, _getElementType["default"])(context);
46 return {
47 JSXOpeningElement: function (_JSXOpeningElement) {
48 function JSXOpeningElement(_x) {
49 return _JSXOpeningElement.apply(this, arguments);
50 }
51 JSXOpeningElement.toString = function () {
52 return _JSXOpeningElement.toString();
53 };
54 return JSXOpeningElement;
55 }(function (node) {
56 var attributes = node.attributes;
57 var type = elementType(node);
58 var _ref = options[0] || {},
59 allowExpressionValues = _ref.allowExpressionValues,
60 _ref$handlers = _ref.handlers,
61 handlers = _ref$handlers === void 0 ? defaultInteractiveProps : _ref$handlers;
62 var hasInteractiveProps = handlers.some(function (prop) {
63 return (0, _jsxAstUtils.hasProp)(attributes, prop) && (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(attributes, prop)) != null;
64 });
65 if (!_ariaQuery.dom.has(type)) {
66 // Do not test higher level JSX components, as we do not know what
67 // low-level DOM element this maps to.
68 return;
69 }
70 if (!hasInteractiveProps || (0, _isHiddenFromScreenReader["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes)) {
71 // Presentation is an intentional signal from the author that this
72 // element is not meant to be perceivable. For example, a click screen
73 // to close a dialog .
74 return;
75 }
76 if ((0, _isInteractiveElement["default"])(type, attributes) || (0, _isInteractiveRole["default"])(type, attributes) || (0, _isNonInteractiveElement["default"])(type, attributes) || (0, _isNonInteractiveRole["default"])(type, attributes) || (0, _isAbstractRole["default"])(type, attributes)) {
77 // This rule has no opinion about abstract roles.
78 return;
79 }
80 if (allowExpressionValues === true && (0, _isNonLiteralProperty["default"])(attributes, 'role')) {
81 // Special case if role is assigned using ternary with literals on both side
82 var roleProp = (0, _jsxAstUtils.getProp)(attributes, 'role');
83 if (roleProp && roleProp.type === 'JSXAttribute' && roleProp.value.type === 'JSXExpressionContainer') {
84 if (roleProp.value.expression.type === 'ConditionalExpression') {
85 if (roleProp.value.expression.consequent.type === 'Literal' && roleProp.value.expression.alternate.type === 'Literal') {
86 return;
87 }
88 }
89 }
90 return;
91 }
92
93 // Visible, non-interactive elements should not have an interactive handler.
94 context.report({
95 node,
96 message: errorMessage
97 });
98 })
99 };
100 }
101};
102module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.