is-inaccessible.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.isInaccessible = isInaccessible;
  4. exports.isSubtreeInaccessible = isSubtreeInaccessible;
  5. /**
  6. * Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
  7. * which should only be used for elements with a non-presentational role i.e.
  8. * `role="none"` and `role="presentation"` will not be excluded.
  9. *
  10. * Implements aria-hidden semantics (i.e. parent overrides child)
  11. * Ignores "Child Presentational: True" characteristics
  12. *
  13. * @param element
  14. * @param options
  15. * @returns {boolean} true if excluded, otherwise false
  16. */
  17. function isInaccessible(element) {
  18. var _element$ownerDocumen;
  19. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20. var _options$getComputedS = options.getComputedStyle,
  21. getComputedStyle = _options$getComputedS === void 0 ? (_element$ownerDocumen = element.ownerDocument.defaultView) === null || _element$ownerDocumen === void 0 ? void 0 : _element$ownerDocumen.getComputedStyle : _options$getComputedS,
  22. _options$isSubtreeIna = options.isSubtreeInaccessible,
  23. isSubtreeInaccessibleImpl = _options$isSubtreeIna === void 0 ? isSubtreeInaccessible : _options$isSubtreeIna;
  24. if (typeof getComputedStyle !== "function") {
  25. throw new TypeError("Owner document of the element needs to have an associated window.");
  26. } // since visibility is inherited we can exit early
  27. if (getComputedStyle(element).visibility === "hidden") {
  28. return true;
  29. }
  30. var currentElement = element;
  31. while (currentElement) {
  32. if (isSubtreeInaccessibleImpl(currentElement, {
  33. getComputedStyle: getComputedStyle
  34. })) {
  35. return true;
  36. }
  37. currentElement = currentElement.parentElement;
  38. }
  39. return false;
  40. }
  41. /**
  42. *
  43. * @param element
  44. * @param options
  45. * @returns {boolean} - `true` if every child of the element is inaccessible
  46. */
  47. function isSubtreeInaccessible(element) {
  48. var _element$ownerDocumen2;
  49. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  50. var _options$getComputedS2 = options.getComputedStyle,
  51. getComputedStyle = _options$getComputedS2 === void 0 ? (_element$ownerDocumen2 = element.ownerDocument.defaultView) === null || _element$ownerDocumen2 === void 0 ? void 0 : _element$ownerDocumen2.getComputedStyle : _options$getComputedS2;
  52. if (typeof getComputedStyle !== "function") {
  53. throw new TypeError("Owner document of the element needs to have an associated window.");
  54. }
  55. if (element.hidden === true) {
  56. return true;
  57. }
  58. if (element.getAttribute("aria-hidden") === "true") {
  59. return true;
  60. }
  61. if (getComputedStyle(element).display === "none") {
  62. return true;
  63. }
  64. return false;
  65. }
  66. //# sourceMappingURL=is-inaccessible.js.map