@royaloperahouse/harmonic 0.13.2-d → 0.13.3-a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3735,6 +3735,7 @@ var Tab = function Tab(_ref) {
3735
3735
  ariaLabel = _ref.ariaLabel,
3736
3736
  tabLinkId = _ref.tabLinkId,
3737
3737
  color = _ref.color,
3738
+ dataTestId = _ref.dataTestId,
3738
3739
  isOpen = _ref.isOpen;
3739
3740
  var clickHandler = function clickHandler() {
3740
3741
  if (onClick) {
@@ -3764,7 +3765,8 @@ var Tab = function Tab(_ref) {
3764
3765
  onFocus: onFocusHandler,
3765
3766
  onKeyDown: onKeyDownHandler,
3766
3767
  tabIndex: 0,
3767
- className: className
3768
+ className: className,
3769
+ "data-testid": dataTestId
3768
3770
  }, /*#__PURE__*/React__default.createElement(TabText, {
3769
3771
  id: tabLinkId,
3770
3772
  trimText: trimText,
@@ -10594,11 +10596,27 @@ var AnchorBar = function AnchorBar(_ref) {
10594
10596
 
10595
10597
  var _templateObject$1e, _templateObject2$Y;
10596
10598
  var FocusableTab = /*#__PURE__*/styled(Tab)(_templateObject$1e || (_templateObject$1e = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n ", "\n &:not(:active):not(:focus) {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: 0;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n border: 0;\n white-space: nowrap;\n user-select: none;\n }\n\n @media ", " {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: 0;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n border: 0;\n white-space: nowrap;\n user-select: none;\n }\n"])), function (_ref) {
10597
- var $hide = _ref.$hide;
10598
- return $hide && "\n display: none;\n ";
10599
+ var hide = _ref.hide;
10600
+ return hide && "display: none;";
10599
10601
  }, devices.mobileAndTablet);
10600
10602
  var HiddenBlock = /*#__PURE__*/styled.div(_templateObject2$Y || (_templateObject2$Y = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n padding: 29px 50px;\n display: inline-block;\n width: 100%;\n height: fit-content;\n border-bottom: solid 2px gray;\n overflow: hidden;\n &:not(:has(div:focus)) {\n border-bottom: 0;\n }\n @media ", " {\n border-bottom: 0;\n }\n"])), devices.mobileAndTablet);
10601
10603
 
10604
+ /**
10605
+ * An accessible component which allows Assistive Technology users to move the focus
10606
+ * to main content, skipping the Nav bar. On desktop, it will remain invisible until focused.
10607
+ * On mobile, it will remain invisible even when focused.
10608
+ *
10609
+ * It's default functionality is to skip to the <main> tag.
10610
+ * However, skipToId may be passed as a prop to target any element with corresponding id.
10611
+ * If neither of those is found in the document, the component will be hidden and not focusable.
10612
+ *
10613
+ * To prevent SSR errors, the component will return `null` when document object is undefined.
10614
+ * In practice, testing reveals that this component renders correctly on most SSR'd pages,
10615
+ * but this check serves as an additional safeguard.
10616
+ *
10617
+ * @param skipToId - an optional id of the element to be skipped to, instead of the default <main> tag target.
10618
+ * @returns JSX.Element | null
10619
+ */
10602
10620
  var SkipToMain = function SkipToMain(_ref) {
10603
10621
  var skipToId = _ref.skipToId;
10604
10622
  var _useState = useState(null),
@@ -10606,21 +10624,43 @@ var SkipToMain = function SkipToMain(_ref) {
10606
10624
  setTargetElement = _useState[1];
10607
10625
  if (typeof document === 'undefined') return null;
10608
10626
  useEffect(function () {
10627
+ var observer = null;
10628
+ var timeoutId;
10629
+ var stopObserving = function stopObserving() {
10630
+ if (observer) {
10631
+ observer.disconnect();
10632
+ observer = null;
10633
+ }
10634
+ clearTimeout(timeoutId);
10635
+ };
10609
10636
  var checkForTarget = function checkForTarget() {
10610
- var element = document.getElementById(skipToId != null ? skipToId : '');
10611
- if (!element) {
10612
- element = document.querySelector('main');
10637
+ var _document$getElementB;
10638
+ var element = (_document$getElementB = document.getElementById(skipToId != null ? skipToId : '')) != null ? _document$getElementB : document.querySelector('main');
10639
+ if (element) {
10640
+ setTargetElement(element);
10641
+ if (observer) {
10642
+ observer.disconnect();
10643
+ observer = null;
10644
+ }
10613
10645
  }
10614
- setTargetElement(element);
10615
10646
  };
10616
10647
  checkForTarget();
10617
- var observer = new MutationObserver(checkForTarget);
10618
- observer.observe(document.body, {
10619
- childList: true,
10620
- subtree: true
10621
- });
10648
+ // NOTE: Potential performance degradation risk from observing the whole document.
10649
+ // Partially mitigated by conditional connecting/disconnecting of observer and the timeout.
10650
+ if (!targetElement) {
10651
+ observer = new MutationObserver(checkForTarget);
10652
+ observer.observe(document.body, {
10653
+ childList: true,
10654
+ subtree: true
10655
+ });
10656
+ var timeoutDuration = 60000;
10657
+ timeoutId = setTimeout(function () {
10658
+ console.warn("SkipToMain: Target element with id \"" + skipToId + "\" not found after " + timeoutDuration / 1000 + " seconds. Stopping observation.");
10659
+ stopObserving();
10660
+ }, timeoutDuration);
10661
+ }
10622
10662
  return function () {
10623
- return observer.disconnect();
10663
+ stopObserving();
10624
10664
  };
10625
10665
  }, []);
10626
10666
  var clickHandler = function clickHandler() {
@@ -10644,9 +10684,10 @@ var SkipToMain = function SkipToMain(_ref) {
10644
10684
  withIcon: "none",
10645
10685
  title: "Skip to main content",
10646
10686
  onClick: clickHandler,
10647
- "$hide": !targetElement,
10687
+ hide: !targetElement,
10648
10688
  ariaLabel: "Skip to main content, in-page",
10649
- role: "link"
10689
+ role: "link",
10690
+ dataTestId: "skip-to-main-button"
10650
10691
  }));
10651
10692
  };
10652
10693