Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

71 wiersze
2.7 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 nonInteractiveRoles = 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. /**
  20. * Returns boolean indicating whether the given element has a role
  21. * that is associated with a non-interactive component. Non-interactive roles
  22. * include `listitem`, `article`, or `dialog`. These are roles that indicate
  23. * for the most part containers.
  24. *
  25. * Elements with these roles should not respond or handle user interactions.
  26. * For example, an `onClick` handler should not be assigned to an element with
  27. * the role `listitem`. An element inside the `listitem`, like a button or a
  28. * link, should handle the click.
  29. *
  30. * This utility returns true for elements that are assigned a non-interactive
  31. * role. It will return false for elements that do not have a role. So whereas
  32. * a `div` might be considered non-interactive, for the purpose of this utility,
  33. * it is considered neither interactive nor non-interactive -- a determination
  34. * cannot be made in this case and false is returned.
  35. */
  36. var 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 = normalizedValues.reduce(function (accumulator, name) {
  46. if ((0, _arrayIncludes2.default)(roles, name)) {
  47. accumulator.push(name);
  48. }
  49. return accumulator;
  50. }, []);
  51. if (validRoles.length > 0) {
  52. // The first role value is a series takes precedence.
  53. isNonInteractive = (0, _arrayIncludes2.default)(nonInteractiveRoles, validRoles[0]);
  54. }
  55. return isNonInteractive;
  56. };
  57. exports.default = isNonInteractiveRole;