source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/util/isNonInteractiveRole.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.4 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 _arrayIncludes = _interopRequireDefault(require("array-includes"));
10var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
11function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12var nonInteractiveRoles = _ariaQuery.roles.keys().filter(function (name) {
13 return !_ariaQuery.roles.get(name)["abstract"] && !_ariaQuery.roles.get(name).superClass.some(function (klasses) {
14 return (0, _arrayIncludes["default"])(klasses, 'widget');
15 });
16});
17
18/**
19 * Returns boolean indicating whether the given element has a role
20 * that is associated with a non-interactive component. Non-interactive roles
21 * include `listitem`, `article`, or `dialog`. These are roles that indicate
22 * for the most part containers.
23 *
24 * Elements with these roles should not respond or handle user interactions.
25 * For example, an `onClick` handler should not be assigned to an element with
26 * the role `listitem`. An element inside the `listitem`, like a button or a
27 * link, should handle the click.
28 *
29 * This utility returns true for elements that are assigned a non-interactive
30 * role. It will return false for elements that do not have a role. So whereas
31 * a `div` might be considered non-interactive, for the purpose of this utility,
32 * it is considered neither interactive nor non-interactive -- a determination
33 * cannot be made in this case and false is returned.
34 */
35
36var isNonInteractiveRole = function isNonInteractiveRole(tagName, attributes) {
37 // Do not test higher level JSX components, as we do not know what
38 // low-level DOM element this maps to.
39 if (!_ariaQuery.dom.has(tagName)) {
40 return false;
41 }
42 var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
43 var isNonInteractive = false;
44 var normalizedValues = String(role).toLowerCase().split(' ');
45 var validRoles = (0, _arrayPrototype["default"])(normalizedValues, function (name) {
46 return _ariaQuery.roles.has(name) ? [name] : [];
47 });
48 if (validRoles.length > 0) {
49 // The first role value is a series takes precedence.
50 isNonInteractive = (0, _arrayIncludes["default"])(nonInteractiveRoles, validRoles[0]);
51 }
52 return isNonInteractive;
53};
54var _default = exports["default"] = isNonInteractiveRole;
55module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.