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

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.d.mts CHANGED
@@ -849,6 +849,7 @@ interface NavigationProps {
849
849
  isOpen: boolean;
850
850
  openButtonRef: RefObject<HTMLButtonElement | null>;
851
851
  linkComponent?: ElementType;
852
+ setKeyboardNavigationClose?: () => void;
852
853
  }
853
854
  type Locale = 'sv' | 'en';
854
855
  type Label = Record<Locale, string>;
package/dist/index.d.ts CHANGED
@@ -849,6 +849,7 @@ interface NavigationProps {
849
849
  isOpen: boolean;
850
850
  openButtonRef: RefObject<HTMLButtonElement | null>;
851
851
  linkComponent?: ElementType;
852
+ setKeyboardNavigationClose?: () => void;
852
853
  }
853
854
  type Locale = 'sv' | 'en';
854
855
  type Label = Record<Locale, string>;
package/dist/index.js CHANGED
@@ -1507,7 +1507,7 @@ var MenuIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("svg", { wid
1507
1507
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("line", { x1: "0.666504", y1: "7", x2: "20.6665", y2: "7", stroke: "#6E3282", strokeWidth: "2" }),
1508
1508
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("line", { x1: "0.666504", y1: "13", x2: "20.6665", y2: "13", stroke: "#6E3282", strokeWidth: "2" })
1509
1509
  ] });
1510
- var ExpandIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1510
+ var ExpandIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1511
1511
  "path",
1512
1512
  {
1513
1513
  fillRule: "evenodd",
@@ -1516,7 +1516,7 @@ var ExpandIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xm
1516
1516
  fill: "white"
1517
1517
  }
1518
1518
  ) });
1519
- var CollapseIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1519
+ var CollapseIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1520
1520
  "path",
1521
1521
  {
1522
1522
  fillRule: "evenodd",
@@ -3802,7 +3802,8 @@ var Navigation = ({
3802
3802
  activatedLanguage = "sv",
3803
3803
  menuLinks = [],
3804
3804
  openButtonRef = null,
3805
- linkComponent: LinkComponent = (props) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("a", { ...props })
3805
+ linkComponent: LinkComponent = (props) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("a", { ...props }),
3806
+ setKeyboardNavigationClose
3806
3807
  }) => {
3807
3808
  const closeMenuText = activatedLanguage === "sv" ? "St\xE4ng meny" : "Close menu";
3808
3809
  const navRef = (0, import_react16.useRef)(null);
@@ -3860,15 +3861,23 @@ var Navigation = ({
3860
3861
  }
3861
3862
  return "\xD6ppna undermeny f\xF6r " + label["sv"];
3862
3863
  };
3863
- const setInstruction = () => {
3864
+ const [instruction, setInstruction] = (0, import_react16.useState)("");
3865
+ (0, import_react16.useEffect)(() => {
3864
3866
  if (firstVisitRef.current) {
3865
3867
  firstVisitRef.current = false;
3866
- return "";
3868
+ return;
3869
+ }
3870
+ setInstruction(
3871
+ isOpen ? activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened" : activatedLanguage === "sv" ? "Navigationsmenyn st\xE4ngdes" : "Navigation menu closed"
3872
+ );
3873
+ }, [isOpen, activatedLanguage]);
3874
+ const handleLinkKeyDown = (event) => {
3875
+ if (event.key === "Enter") {
3876
+ setKeyboardNavigationClose == null ? void 0 : setKeyboardNavigationClose();
3867
3877
  }
3868
- return isOpen ? activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened" : activatedLanguage === "sv" ? "Navigationsmenyn st\xE4ngdes" : "Navigation menu closed";
3869
3878
  };
3870
3879
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
3871
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { "aria-live": "polite", className: "sr-only", children: setInstruction() }),
3880
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { "aria-live": "polite", className: "sr-only", children: instruction }),
3872
3881
  /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
3873
3882
  "nav",
3874
3883
  {
@@ -3897,7 +3906,15 @@ var Navigation = ({
3897
3906
  lang: activatedLanguage,
3898
3907
  children: [
3899
3908
  /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "pts-navigation-button", children: [
3900
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: href && href.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(LinkComponent, { onClick: handleCloseButton, href, children: label[activatedLanguage] }) }),
3909
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: href && href.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3910
+ LinkComponent,
3911
+ {
3912
+ onClick: handleCloseButton,
3913
+ href,
3914
+ onKeyDown: handleLinkKeyDown,
3915
+ children: label[activatedLanguage]
3916
+ }
3917
+ ) }),
3901
3918
  children && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3902
3919
  "button",
3903
3920
  {
@@ -3920,7 +3937,15 @@ var Navigation = ({
3920
3937
  className: "pts-sub-navigation-container",
3921
3938
  id: "sub-menu-" + index,
3922
3939
  role: "region",
3923
- children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(LinkComponent, { onClick: handleCloseButton, href: href2, children: label2[activatedLanguage] }) }, "nav-child-" + index2)) })
3940
+ children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3941
+ LinkComponent,
3942
+ {
3943
+ onClick: handleCloseButton,
3944
+ href: href2,
3945
+ onKeyDown: handleLinkKeyDown,
3946
+ children: label2[activatedLanguage]
3947
+ }
3948
+ ) }, "nav-child-" + index2)) })
3924
3949
  }
3925
3950
  )
3926
3951
  ]
@@ -4015,14 +4040,14 @@ var NavigationHeader = ({
4015
4040
  };
4016
4041
  const [isMenuOpen, setIsMenuOpen] = (0, import_react18.useState)(false);
4017
4042
  const [hasBeenOpen, setHasBeenOpen] = (0, import_react18.useState)(false);
4043
+ const shouldRestoreFocusRef = (0, import_react18.useRef)(false);
4018
4044
  (0, import_react18.useEffect)(() => {
4019
4045
  var _a;
4020
- console.log(navigationCloseFocusId);
4021
- if (!isMenuOpen && navigationCloseFocusId && hasBeenOpen) {
4046
+ if (!isMenuOpen && navigationCloseFocusId && hasBeenOpen && shouldRestoreFocusRef.current) {
4022
4047
  (_a = document.getElementById(navigationCloseFocusId)) == null ? void 0 : _a.focus();
4023
- console.log(navigationCloseFocusId, document.getElementById(navigationCloseFocusId));
4048
+ shouldRestoreFocusRef.current = false;
4024
4049
  }
4025
- }, [isMenuOpen]);
4050
+ }, [isMenuOpen, navigationCloseFocusId, hasBeenOpen]);
4026
4051
  const handleMenuClick = () => {
4027
4052
  setIsMenuOpen((prev) => {
4028
4053
  const open = !prev;
@@ -4116,7 +4141,10 @@ var NavigationHeader = ({
4116
4141
  menuLinks,
4117
4142
  isOpen: isMenuOpen,
4118
4143
  openButtonRef: menuButtonFocusRef,
4119
- linkComponent: LinkComponent
4144
+ linkComponent: LinkComponent,
4145
+ setKeyboardNavigationClose: () => {
4146
+ shouldRestoreFocusRef.current = true;
4147
+ }
4120
4148
  }
4121
4149
  ),
4122
4150
  isMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
@@ -4290,7 +4318,7 @@ var Collapse = ({
4290
4318
  "aria-controls": contentId,
4291
4319
  children: [
4292
4320
  `${isOpen ? closeLabel : openLabel} ${title}`,
4293
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "pts-open-close-icon", "aria-hidden": "true", children: isOpen ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CollapseIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ExpandIcon, {}) })
4321
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "pts-collapse-open-close-icon", "aria-hidden": "true", children: isOpen ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CollapseIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ExpandIcon, {}) })
4294
4322
  ]
4295
4323
  }
4296
4324
  ),