Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

68 rindas
2.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _ariaQuery = require('aria-query');
  6. var _jsxAstUtils = require('jsx-ast-utils');
  7. var _arrayIncludes = require('array-includes');
  8. var _arrayIncludes2 = _interopRequireDefault(_arrayIncludes);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  11. var roles = [].concat(_toConsumableArray(_ariaQuery.roles.keys()));
  12. var interactiveRoles = roles.filter(function (name) {
  13. return !_ariaQuery.roles.get(name).abstract;
  14. }).filter(function (name) {
  15. return _ariaQuery.roles.get(name).superClass.some(function (klasses) {
  16. return (0, _arrayIncludes2.default)(klasses, 'widget');
  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. // If value is undefined, then the role attribute will be dropped in the DOM.
  36. // If value is null, then getLiteralAttributeValue is telling us that the
  37. // value isn't in the form of a literal
  38. if (value === undefined || value === null) {
  39. return false;
  40. }
  41. var isInteractive = false;
  42. var normalizedValues = String(value).toLowerCase().split(' ');
  43. var validRoles = normalizedValues.reduce(function (accumulator, name) {
  44. if ((0, _arrayIncludes2.default)(roles, name)) {
  45. accumulator.push(name);
  46. }
  47. return accumulator;
  48. }, []);
  49. if (validRoles.length > 0) {
  50. // The first role value is a series takes precedence.
  51. isInteractive = (0, _arrayIncludes2.default)(interactiveRoles, validRoles[0]);
  52. }
  53. return isInteractive;
  54. };
  55. exports.default = isInteractiveRole;