| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _ariaQuery = require("aria-query");
|
|---|
| 8 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 9 | var _arrayIncludes = _interopRequireDefault(require("array-includes"));
|
|---|
| 10 | var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
|
|---|
| 11 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|---|
| 12 | var roles = _ariaQuery.roles.keys();
|
|---|
| 13 | var 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.
|
|---|
| 21 | interactiveRoles.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 | */
|
|---|
| 33 | var 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 | };
|
|---|
| 53 | var _default = exports["default"] = isInteractiveRole;
|
|---|
| 54 | module.exports = exports.default; |
|---|