optimized-react-component-library-xyz123 2.8.4 → 2.8.6

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/index.mjs CHANGED
@@ -3719,18 +3719,19 @@ var Navigation = ({
3719
3719
  activatedLanguage = "sv",
3720
3720
  menuLinks = [],
3721
3721
  openButtonRef = null,
3722
- linkComponent: LinkComponent = (props) => /* @__PURE__ */ jsx28("a", { ...props }),
3723
- setKeyboardNavigationClose
3722
+ linkComponent: LinkComponent = (props) => /* @__PURE__ */ jsx28("a", { ...props })
3723
+ //setKeyboardNavigationClose,
3724
3724
  }) => {
3725
3725
  const closeMenuText = activatedLanguage === "sv" ? "St\xE4ng meny" : "Close menu";
3726
3726
  const navRef = useRef3(null);
3727
- const firstVisitRef = useRef3(true);
3728
3727
  const [openSubMenu, setOpenSubMenu] = useState9(null);
3729
3728
  const handleSubMenu = (label) => {
3730
3729
  setOpenSubMenu(openSubMenu === label ? null : label);
3731
3730
  };
3732
- const handleCloseButton = () => {
3731
+ const handleCloseButton = (type) => {
3732
+ var _a, _b;
3733
3733
  setIsMenyOpen && setIsMenyOpen(false);
3734
+ type === "close" ? (_a = openButtonRef == null ? void 0 : openButtonRef.current) == null ? void 0 : _a.focus() : (_b = document.getElementById("page-start")) == null ? void 0 : _b.focus();
3734
3735
  };
3735
3736
  useEffect13(() => {
3736
3737
  if (!isOpen || !navRef.current) return;
@@ -3740,7 +3741,9 @@ var Navigation = ({
3740
3741
  const firstElement = focusableElements[0];
3741
3742
  const lastElement = focusableElements[focusableElements.length - 1];
3742
3743
  if (!firstElement || !lastElement) return;
3743
- firstElement == null ? void 0 : firstElement.focus();
3744
+ requestAnimationFrame(() => {
3745
+ firstElement.focus();
3746
+ });
3744
3747
  const handleKeyDown = (event) => {
3745
3748
  var _a;
3746
3749
  if (event.key === "Escape") {
@@ -3778,101 +3781,85 @@ var Navigation = ({
3778
3781
  }
3779
3782
  return "\xD6ppna undermeny f\xF6r " + label["sv"];
3780
3783
  };
3781
- const [instruction, setInstruction] = useState9("");
3782
- useEffect13(() => {
3783
- if (firstVisitRef.current) {
3784
- firstVisitRef.current = false;
3785
- return;
3786
- }
3787
- setInstruction(
3788
- isOpen ? activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened" : activatedLanguage === "sv" ? "Navigationsmenyn st\xE4ngdes" : "Navigation menu closed"
3789
- );
3790
- }, [isOpen, activatedLanguage]);
3791
- const handleLinkKeyDown = (event) => {
3792
- if (event.key === "Enter") {
3793
- setKeyboardNavigationClose == null ? void 0 : setKeyboardNavigationClose();
3794
- }
3795
- };
3796
- return /* @__PURE__ */ jsxs24(Fragment18, { children: [
3797
- /* @__PURE__ */ jsx28("div", { "aria-live": "polite", className: "sr-only", children: instruction }),
3798
- /* @__PURE__ */ jsxs24(
3799
- "nav",
3800
- {
3801
- id: "main-navigation",
3802
- ref: navRef,
3803
- "aria-label": activatedLanguage === "sv" ? "Huvudnavigation" : "Main navigation",
3804
- className: `pts-navigation-menu-container ${isOpen ? "open" : ""}`,
3805
- inert: !isOpen,
3806
- children: [
3807
- /* @__PURE__ */ jsx28("div", { className: "pts-navigation-close-container ", id: "menu-close", children: /* @__PURE__ */ jsxs24(
3808
- "button",
3809
- {
3810
- className: "pts-navigation-close-button",
3811
- onClick: handleCloseButton,
3812
- type: "button",
3813
- children: [
3814
- /* @__PURE__ */ jsx28("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx28(CloseIcon, {}) }),
3815
- /* @__PURE__ */ jsx28("span", { className: "pts-navigation-close-text", children: closeMenuText })
3816
- ]
3817
- }
3818
- ) }),
3819
- /* @__PURE__ */ jsx28("ul", { className: "pts-navigation-link-list", lang: activatedLanguage, children: menuLinks && menuLinks.map(({ label, href, children }, index) => /* @__PURE__ */ jsxs24(
3820
- "li",
3821
- {
3822
- className: `pts-navigation-link ${openSubMenu === label[activatedLanguage] ? "open" : ""}`,
3823
- lang: activatedLanguage,
3824
- children: [
3825
- /* @__PURE__ */ jsx28("div", { children: /* @__PURE__ */ jsxs24("div", { className: "pts-navigation-button", children: [
3826
- /* @__PURE__ */ jsx28("span", { children: href && href.length === 0 ? /* @__PURE__ */ jsx28("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ jsx28(
3827
- LinkComponent,
3828
- {
3829
- onClick: handleCloseButton,
3830
- href,
3831
- onKeyDown: handleLinkKeyDown,
3832
- children: label[activatedLanguage]
3833
- }
3834
- ) }),
3835
- children && /* @__PURE__ */ jsx28(
3836
- "button",
3837
- {
3838
- className: `pts-navigation-link-expand-button`,
3839
- onClick: () => handleSubMenu(label[activatedLanguage]),
3840
- "aria-label": getSubMenuAriaLabel(label),
3841
- "aria-expanded": openSubMenu === label[activatedLanguage],
3842
- "aria-controls": "sub-menu-" + index,
3843
- type: "button",
3844
- id: "menu-button-" + index,
3845
- children: openSubMenu === label[activatedLanguage] ? /* @__PURE__ */ jsx28("span", { "aria-hidden": true, className: "pts-contract-icon", children: /* @__PURE__ */ jsx28(MinusIcon, {}) }) : /* @__PURE__ */ jsx28("span", { "aria-hidden": true, className: "pts-expand-icon", children: /* @__PURE__ */ jsx28(AddIcon, {}) })
3846
- }
3847
- )
3848
- ] }) }),
3784
+ return /* @__PURE__ */ jsx28(Fragment18, { children: /* @__PURE__ */ jsxs24(
3785
+ "nav",
3786
+ {
3787
+ id: "main-navigation",
3788
+ ref: navRef,
3789
+ "aria-label": activatedLanguage === "sv" ? "Huvudnavigation" : "Main navigation",
3790
+ className: `pts-navigation-menu-container ${isOpen ? "open" : ""}`,
3791
+ inert: !isOpen,
3792
+ children: [
3793
+ /* @__PURE__ */ jsx28("div", { className: "pts-navigation-close-container ", id: "menu-close", children: /* @__PURE__ */ jsxs24(
3794
+ "button",
3795
+ {
3796
+ className: "pts-navigation-close-button",
3797
+ onClick: () => handleCloseButton("close"),
3798
+ type: "button",
3799
+ children: [
3800
+ /* @__PURE__ */ jsx28("span", { "aria-hidden": "true", children: /* @__PURE__ */ jsx28(CloseIcon, {}) }),
3801
+ /* @__PURE__ */ jsx28("span", { className: "pts-navigation-close-text", children: closeMenuText })
3802
+ ]
3803
+ }
3804
+ ) }),
3805
+ /* @__PURE__ */ jsx28("ul", { className: "pts-navigation-link-list", lang: activatedLanguage, children: menuLinks && menuLinks.map(({ label, href, children }, index) => /* @__PURE__ */ jsxs24(
3806
+ "li",
3807
+ {
3808
+ className: `pts-navigation-link ${openSubMenu === label[activatedLanguage] ? "open" : ""}`,
3809
+ lang: activatedLanguage,
3810
+ children: [
3811
+ /* @__PURE__ */ jsx28("div", { children: /* @__PURE__ */ jsxs24("div", { className: "pts-navigation-button", children: [
3812
+ /* @__PURE__ */ jsx28("span", { children: href && href.length === 0 ? /* @__PURE__ */ jsx28("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ jsx28(
3813
+ LinkComponent,
3814
+ {
3815
+ onClick: () => {
3816
+ handleCloseButton("link");
3817
+ },
3818
+ href,
3819
+ children: label[activatedLanguage]
3820
+ }
3821
+ ) }),
3849
3822
  children && /* @__PURE__ */ jsx28(
3850
- "div",
3823
+ "button",
3851
3824
  {
3852
- hidden: openSubMenu !== label[activatedLanguage],
3853
- "aria-hidden": openSubMenu !== label[activatedLanguage],
3854
- className: "pts-sub-navigation-container",
3855
- id: "sub-menu-" + index,
3856
- role: "region",
3857
- children: /* @__PURE__ */ jsx28("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ jsx28("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ jsx28(
3858
- LinkComponent,
3859
- {
3860
- onClick: handleCloseButton,
3861
- href: href2,
3862
- onKeyDown: handleLinkKeyDown,
3863
- children: label2[activatedLanguage]
3864
- }
3865
- ) }, "nav-child-" + index2)) })
3825
+ className: `pts-navigation-link-expand-button`,
3826
+ onClick: () => handleSubMenu(label[activatedLanguage]),
3827
+ "aria-label": getSubMenuAriaLabel(label),
3828
+ "aria-expanded": openSubMenu === label[activatedLanguage],
3829
+ "aria-controls": "sub-menu-" + index,
3830
+ type: "button",
3831
+ id: "menu-button-" + index,
3832
+ children: openSubMenu === label[activatedLanguage] ? /* @__PURE__ */ jsx28("span", { "aria-hidden": true, className: "pts-contract-icon", children: /* @__PURE__ */ jsx28(MinusIcon, {}) }) : /* @__PURE__ */ jsx28("span", { "aria-hidden": true, className: "pts-expand-icon", children: /* @__PURE__ */ jsx28(AddIcon, {}) })
3866
3833
  }
3867
3834
  )
3868
- ]
3869
- },
3870
- "nav-" + index
3871
- )) })
3872
- ]
3873
- }
3874
- )
3875
- ] });
3835
+ ] }) }),
3836
+ children && /* @__PURE__ */ jsx28(
3837
+ "div",
3838
+ {
3839
+ hidden: openSubMenu !== label[activatedLanguage],
3840
+ "aria-hidden": openSubMenu !== label[activatedLanguage],
3841
+ className: "pts-sub-navigation-container",
3842
+ id: "sub-menu-" + index,
3843
+ role: "region",
3844
+ children: /* @__PURE__ */ jsx28("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ jsx28("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ jsx28(
3845
+ LinkComponent,
3846
+ {
3847
+ onClick: () => {
3848
+ handleCloseButton("link");
3849
+ },
3850
+ href: href2,
3851
+ children: label2[activatedLanguage]
3852
+ }
3853
+ ) }, "nav-child-" + index2)) })
3854
+ }
3855
+ )
3856
+ ]
3857
+ },
3858
+ "nav-" + index
3859
+ )) })
3860
+ ]
3861
+ }
3862
+ ) });
3876
3863
  };
3877
3864
  var NavigationStandard_default = Navigation;
3878
3865
 
@@ -3943,7 +3930,6 @@ var NavigationHeader = ({
3943
3930
  }) => {
3944
3931
  const logoLink = activatedLanguage === "en" ? "https://pts.se/en" : "https://pts.se/";
3945
3932
  const hasHeadline = headline && headline.length > 0;
3946
- const menuButtonFocusRef = useRef4(null);
3947
3933
  const handleLanguageClick = () => {
3948
3934
  if (activatedLanguage === "sv") {
3949
3935
  SetActivatedLanguage("en");
@@ -3957,14 +3943,7 @@ var NavigationHeader = ({
3957
3943
  };
3958
3944
  const [isMenuOpen, setIsMenuOpen] = useState11(false);
3959
3945
  const [hasBeenOpen, setHasBeenOpen] = useState11(false);
3960
- const shouldRestoreFocusRef = useRef4(false);
3961
- useEffect14(() => {
3962
- var _a;
3963
- if (!isMenuOpen && navigationCloseFocusId && hasBeenOpen && shouldRestoreFocusRef.current) {
3964
- (_a = document.getElementById(navigationCloseFocusId)) == null ? void 0 : _a.focus();
3965
- shouldRestoreFocusRef.current = false;
3966
- }
3967
- }, [isMenuOpen, navigationCloseFocusId, hasBeenOpen]);
3946
+ const menuButtonFocusRef = useRef4(null);
3968
3947
  const handleMenuClick = () => {
3969
3948
  setIsMenuOpen((prev) => {
3970
3949
  const open = !prev;
@@ -3974,6 +3953,15 @@ var NavigationHeader = ({
3974
3953
  return open;
3975
3954
  });
3976
3955
  };
3956
+ const [instruction, setInstruction] = useState11("");
3957
+ useEffect14(() => {
3958
+ if (!hasBeenOpen) {
3959
+ return;
3960
+ }
3961
+ setInstruction(
3962
+ isMenuOpen ? activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened" : activatedLanguage === "sv" ? "Navigationsmenyn st\xE4ngdes" : "Navigation menu closed"
3963
+ );
3964
+ }, [isMenuOpen, activatedLanguage]);
3977
3965
  const getMenuLabel = () => {
3978
3966
  const labels = {
3979
3967
  sv: isMenuOpen ? "St\xE4ng meny" : "Meny",
@@ -4050,20 +4038,22 @@ var NavigationHeader = ({
4050
4038
  )
4051
4039
  ] }) })
4052
4040
  ] }) }),
4053
- useNavigationMenu && /* @__PURE__ */ jsx31(
4054
- NavigationStandard_default,
4055
- {
4056
- activatedLanguage,
4057
- setIsMenyOpen: setIsMenuOpen,
4058
- menuLinks,
4059
- isOpen: isMenuOpen,
4060
- openButtonRef: menuButtonFocusRef,
4061
- linkComponent: LinkComponent,
4062
- setKeyboardNavigationClose: () => {
4063
- shouldRestoreFocusRef.current = true;
4041
+ useNavigationMenu && /* @__PURE__ */ jsxs27(Fragment19, { children: [
4042
+ /* @__PURE__ */ jsx31("div", { "aria-live": "polite", className: "sr-only", children: instruction }),
4043
+ /* @__PURE__ */ jsx31(
4044
+ NavigationStandard_default,
4045
+ {
4046
+ activatedLanguage,
4047
+ setIsMenyOpen: setIsMenuOpen,
4048
+ menuLinks,
4049
+ isOpen: isMenuOpen,
4050
+ openButtonRef: menuButtonFocusRef,
4051
+ linkComponent: LinkComponent,
4052
+ setKeyboardNavigationClose: () => {
4053
+ }
4064
4054
  }
4065
- }
4066
- ),
4055
+ )
4056
+ ] }),
4067
4057
  isMenuOpen && /* @__PURE__ */ jsx31(
4068
4058
  "div",
4069
4059
  {