You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.6KB

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