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

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.3 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 roles = _ariaQuery.roles.keys();
13var interactiveRoles = roles.filter(function (name) {
14 return !_ariaQuery.roles.get(name)["abstract"] && _ariaQuery.roles.get(name).superClass.some(function (klasses) {
15 return (0, _arrayIncludes["default"])(klasses, 'widget');
16 });
17});
18
19// 'toolbar' does not descend from widget, but it does support
20// aria-activedescendant, thus in practice we treat it as a widget.
21interactiveRoles.push('toolbar');
22/**
23 * Returns boolean indicating whether the given element has a role
24 * that is associated with an interactive component. Used when an element
25 * has a dynamic handler on it and we need to discern whether or not
26 * its intention is to be interacted with in the DOM.
27 *
28 * isInteractiveRole is a Logical Disjunction:
29 * https://en.wikipedia.org/wiki/Logical_disjunction
30 * The JSX element does not have a tagName or it has a tagName and a role
31 * attribute with a value in the set of non-interactive roles.
32 */
33var isInteractiveRole = function isInteractiveRole(tagName, attributes) {
34 var value = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
35
36 // If value is undefined, then the role attribute will be dropped in the DOM.
37 // If value is null, then getLiteralAttributeValue is telling us that the
38 // value isn't in the form of a literal
39 if (value === undefined || value === null) {
40 return false;
41 }
42 var isInteractive = false;
43 var normalizedValues = String(value).toLowerCase().split(' ');
44 var validRoles = (0, _arrayPrototype["default"])(normalizedValues, function (name) {
45 return (0, _arrayIncludes["default"])(roles, name) ? [name] : [];
46 });
47 if (validRoles.length > 0) {
48 // The first role value is a series takes precedence.
49 isInteractive = (0, _arrayIncludes["default"])(interactiveRoles, validRoles[0]);
50 }
51 return isInteractive;
52};
53var _default = exports["default"] = isInteractiveRole;
54module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.