@mirohq/design-system-calendar 2.5.10 → 2.5.11

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.
package/dist/module.js CHANGED
@@ -696,6 +696,37 @@ const Header = ({
696
696
  }
697
697
  return "";
698
698
  };
699
+ const prevButtonRef = useRef(null);
700
+ const nextButtonRef = useRef(null);
701
+ const titleButtonRef = useRef(null);
702
+ const focusedStepRef = useRef(null);
703
+ useLayoutEffect(() => {
704
+ var _a;
705
+ const focusedStep = focusedStepRef.current;
706
+ if (focusedStep === null) return;
707
+ const isPrev = focusedStep === "prev";
708
+ const isFocusedStepDisabled = (isPrev ? isPrevDisabled : isNextDisabled) === true;
709
+ if (!isFocusedStepDisabled) return;
710
+ const disabledButton = isPrev ? prevButtonRef.current : nextButtonRef.current;
711
+ const otherButton = isPrev ? nextButtonRef.current : prevButtonRef.current;
712
+ const activeElement = disabledButton == null ? void 0 : disabledButton.ownerDocument.activeElement;
713
+ focusedStepRef.current = null;
714
+ if (activeElement != null && activeElement !== disabledButton && activeElement !== (disabledButton == null ? void 0 : disabledButton.ownerDocument.body)) {
715
+ return;
716
+ }
717
+ const fallback = (_a = titleButtonRef.current) != null ? _a : (otherButton == null ? void 0 : otherButton.disabled) === false ? otherButton : null;
718
+ fallback == null ? void 0 : fallback.focus();
719
+ }, [isPrevDisabled, isNextDisabled]);
720
+ const trackStepFocus = (step) => ({
721
+ onFocus: () => {
722
+ focusedStepRef.current = step;
723
+ },
724
+ // A button that disables itself blurs with no relatedTarget; keep tracking
725
+ // it so the effect above can still hand focus on.
726
+ onBlur: (event) => {
727
+ if (event.relatedTarget !== null) focusedStepRef.current = null;
728
+ }
729
+ });
699
730
  const isTopLevel = viewMode === "years";
700
731
  const showClickableTitle = navigation === true && !isTopLevel;
701
732
  const isDayView = viewMode === "days";
@@ -707,15 +738,18 @@ const Header = ({
707
738
  isDayView ? /* @__PURE__ */ jsx(HeaderButton, { ...prevButtonProps, children: /* @__PURE__ */ jsx(IconChevronLeft, {}) }) : /* @__PURE__ */ jsx(
708
739
  HeaderButton,
709
740
  {
741
+ ref: prevButtonRef,
710
742
  "aria-label": stepLabels.prev,
711
743
  isDisabled: isPrevDisabled,
712
744
  onClick: onPrevOverride,
745
+ ...trackStepFocus("prev"),
713
746
  children: /* @__PURE__ */ jsx(IconChevronLeft, {})
714
747
  }
715
748
  ),
716
749
  /* @__PURE__ */ jsx(StyledHeaderTitle, { level: 2, styledAs: "h3", children: showClickableTitle ? /* @__PURE__ */ jsx(
717
750
  StyledHeaderTitleButton,
718
751
  {
752
+ ref: titleButtonRef,
719
753
  onClick: onZoomOut,
720
754
  "aria-label": (formatSwitchViewLabel != null ? formatSwitchViewLabel : strings.switchView)(
721
755
  getTitleText(),
@@ -733,9 +767,11 @@ const Header = ({
733
767
  isDayView ? /* @__PURE__ */ jsx(HeaderButton, { ...nextButtonProps, children: /* @__PURE__ */ jsx(IconChevronRight, {}) }) : /* @__PURE__ */ jsx(
734
768
  HeaderButton,
735
769
  {
770
+ ref: nextButtonRef,
736
771
  "aria-label": stepLabels.next,
737
772
  isDisabled: isNextDisabled,
738
773
  onClick: onNextOverride,
774
+ ...trackStepFocus("next"),
739
775
  children: /* @__PURE__ */ jsx(IconChevronRight, {})
740
776
  }
741
777
  )