optimized-react-component-library-xyz123 2.8.22 → 2.9.2

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
@@ -846,6 +846,7 @@ interface NavigationHeaderProps {
846
846
  menuLinks: INavigationItem[];
847
847
  linkComponent?: ElementType;
848
848
  noLogoLink?: boolean;
849
+ navigationCloseFocusId?: string;
849
850
  }
850
851
 
851
852
  declare const NavigationHeader: FC<NavigationHeaderProps>;
@@ -857,6 +858,7 @@ interface NavigationProps {
857
858
  isOpen: boolean;
858
859
  openButtonRef: RefObject<HTMLButtonElement | null>;
859
860
  linkComponent?: ElementType;
861
+ navigationCloseFocusId?: string;
860
862
  }
861
863
  type Locale = 'sv' | 'en';
862
864
  type Label = Record<Locale, string>;
package/dist/index.d.ts CHANGED
@@ -846,6 +846,7 @@ interface NavigationHeaderProps {
846
846
  menuLinks: INavigationItem[];
847
847
  linkComponent?: ElementType;
848
848
  noLogoLink?: boolean;
849
+ navigationCloseFocusId?: string;
849
850
  }
850
851
 
851
852
  declare const NavigationHeader: FC<NavigationHeaderProps>;
@@ -857,6 +858,7 @@ interface NavigationProps {
857
858
  isOpen: boolean;
858
859
  openButtonRef: RefObject<HTMLButtonElement | null>;
859
860
  linkComponent?: ElementType;
861
+ navigationCloseFocusId?: string;
860
862
  }
861
863
  type Locale = 'sv' | 'en';
862
864
  type Label = Record<Locale, string>;
package/dist/index.js CHANGED
@@ -1509,7 +1509,7 @@ var MenuIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("svg", { wid
1509
1509
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("line", { x1: "0.666504", y1: "7", x2: "20.6665", y2: "7", stroke: "#6E3282", strokeWidth: "2" }),
1510
1510
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("line", { x1: "0.666504", y1: "13", x2: "20.6665", y2: "13", stroke: "#6E3282", strokeWidth: "2" })
1511
1511
  ] });
1512
- 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)(
1512
+ 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)(
1513
1513
  "path",
1514
1514
  {
1515
1515
  fillRule: "evenodd",
@@ -1518,7 +1518,7 @@ var ExpandIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { xm
1518
1518
  fill: "white"
1519
1519
  }
1520
1520
  ) });
1521
- 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)(
1521
+ 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)(
1522
1522
  "path",
1523
1523
  {
1524
1524
  fillRule: "evenodd",
@@ -3965,16 +3965,20 @@ var Navigation = ({
3965
3965
  activatedLanguage = "sv",
3966
3966
  menuLinks = [],
3967
3967
  openButtonRef = null,
3968
- linkComponent: LinkComponent = (props) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("a", { ...props })
3968
+ linkComponent: LinkComponent = (props) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("a", { ...props }),
3969
+ navigationCloseFocusId
3969
3970
  }) => {
3970
3971
  const closeMenuText = activatedLanguage === "sv" ? "St\xE4ng meny" : "Close menu";
3971
3972
  const navRef = (0, import_react16.useRef)(null);
3973
+ const firstVisitRef = (0, import_react16.useRef)(true);
3972
3974
  const [openSubMenu, setOpenSubMenu] = (0, import_react16.useState)(null);
3973
3975
  const handleSubMenu = (label) => {
3974
3976
  setOpenSubMenu(openSubMenu === label ? null : label);
3975
3977
  };
3976
- const handleCloseButton = () => {
3977
- setIsMenyOpen && setIsMenyOpen(false);
3978
+ const handleMenuClick = (typeOfInteraction) => {
3979
+ var _a, _b;
3980
+ setIsMenyOpen == null ? void 0 : setIsMenyOpen(false);
3981
+ typeOfInteraction === "close" ? (_a = openButtonRef == null ? void 0 : openButtonRef.current) == null ? void 0 : _a.focus() : navigationCloseFocusId && ((_b = document.getElementById(navigationCloseFocusId)) == null ? void 0 : _b.focus());
3978
3982
  };
3979
3983
  (0, import_react16.useEffect)(() => {
3980
3984
  if (!isOpen || !navRef.current) return;
@@ -3984,7 +3988,9 @@ var Navigation = ({
3984
3988
  const firstElement = focusableElements[0];
3985
3989
  const lastElement = focusableElements[focusableElements.length - 1];
3986
3990
  if (!firstElement || !lastElement) return;
3987
- firstElement == null ? void 0 : firstElement.focus();
3991
+ requestAnimationFrame(() => {
3992
+ firstElement.focus();
3993
+ });
3988
3994
  const handleKeyDown = (event) => {
3989
3995
  var _a;
3990
3996
  if (event.key === "Escape") {
@@ -4022,8 +4028,21 @@ var Navigation = ({
4022
4028
  }
4023
4029
  return "\xD6ppna undermeny f\xF6r " + label["sv"];
4024
4030
  };
4031
+ const [instruction, setInstruction] = (0, import_react16.useState)("");
4032
+ (0, import_react16.useEffect)(() => {
4033
+ if (firstVisitRef.current) {
4034
+ firstVisitRef.current = false;
4035
+ return;
4036
+ }
4037
+ if (isOpen)
4038
+ requestAnimationFrame(() => {
4039
+ setInstruction(
4040
+ activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened"
4041
+ );
4042
+ });
4043
+ }, [isOpen, activatedLanguage]);
4025
4044
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
4026
- /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { "aria-live": "polite", className: "sr-only", children: isOpen ? activatedLanguage === "sv" ? "Navigationsmenyn \xF6ppnades" : "Navigation menu opened" : activatedLanguage === "sv" ? "Navigationsmenyn st\xE4ngdes" : "Navigation menu closed" }),
4045
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { "aria-live": "polite", className: "sr-only", children: instruction }),
4027
4046
  /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
4028
4047
  "nav",
4029
4048
  {
@@ -4032,12 +4051,13 @@ var Navigation = ({
4032
4051
  "aria-label": activatedLanguage === "sv" ? "Huvudnavigation" : "Main navigation",
4033
4052
  className: `pts-navigation-menu-container ${isOpen ? "open" : ""}`,
4034
4053
  inert: !isOpen,
4054
+ "aria-expanded": isOpen,
4035
4055
  children: [
4036
4056
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "pts-navigation-close-container ", id: "menu-close", children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
4037
4057
  "button",
4038
4058
  {
4039
4059
  className: "pts-navigation-close-button",
4040
- onClick: handleCloseButton,
4060
+ onClick: () => handleMenuClick("close"),
4041
4061
  type: "button",
4042
4062
  children: [
4043
4063
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(CloseIcon, {}) }),
@@ -4052,7 +4072,14 @@ var Navigation = ({
4052
4072
  lang: activatedLanguage,
4053
4073
  children: [
4054
4074
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "pts-navigation-button", children: [
4055
- /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: href && href.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(LinkComponent, { onClick: handleCloseButton, href, children: label[activatedLanguage] }) }),
4075
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: href && href.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: label[activatedLanguage] }) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4076
+ LinkComponent,
4077
+ {
4078
+ onClick: () => handleMenuClick("link"),
4079
+ href,
4080
+ children: label[activatedLanguage]
4081
+ }
4082
+ ) }),
4056
4083
  children && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4057
4084
  "button",
4058
4085
  {
@@ -4075,7 +4102,14 @@ var Navigation = ({
4075
4102
  className: "pts-sub-navigation-container",
4076
4103
  id: "sub-menu-" + index,
4077
4104
  role: "region",
4078
- children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(LinkComponent, { onClick: handleCloseButton, href: href2, children: label2[activatedLanguage] }) }, "nav-child-" + index2)) })
4105
+ children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("ul", { className: "pts-sub-navigation-list", lang: activatedLanguage, children: children.map(({ label: label2, href: href2 }, index2) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("li", { className: "pts-sub-navigation-item", lang: activatedLanguage, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4106
+ LinkComponent,
4107
+ {
4108
+ onClick: () => handleMenuClick("link"),
4109
+ href: href2,
4110
+ children: label2[activatedLanguage]
4111
+ }
4112
+ ) }, "nav-child-" + index2)) })
4079
4113
  }
4080
4114
  )
4081
4115
  ]
@@ -4151,11 +4185,11 @@ var NavigationHeader = ({
4151
4185
  SetActivatedLanguage = () => {
4152
4186
  },
4153
4187
  linkComponent: LinkComponent = (props) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("a", { ...props }),
4154
- noLogoLink = false
4188
+ noLogoLink = false,
4189
+ navigationCloseFocusId
4155
4190
  }) => {
4156
4191
  const logoLink = activatedLanguage === "en" ? "https://pts.se/en" : "https://pts.se/";
4157
4192
  const hasHeadline = headline && headline.length > 0;
4158
- const menuButtonFocusRef = (0, import_react18.useRef)(null);
4159
4193
  const handleLanguageClick = () => {
4160
4194
  if (activatedLanguage === "sv") {
4161
4195
  SetActivatedLanguage("en");
@@ -4168,6 +4202,7 @@ var NavigationHeader = ({
4168
4202
  else return "Svenska";
4169
4203
  };
4170
4204
  const [isMenuOpen, setIsMenuOpen] = (0, import_react18.useState)(false);
4205
+ const menuButtonFocusRef = (0, import_react18.useRef)(null);
4171
4206
  const handleMenuClick = () => {
4172
4207
  setIsMenuOpen((prev) => !prev);
4173
4208
  };
@@ -4247,7 +4282,7 @@ var NavigationHeader = ({
4247
4282
  )
4248
4283
  ] }) })
4249
4284
  ] }) }),
4250
- useNavigationMenu && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4285
+ useNavigationMenu && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_jsx_runtime33.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4251
4286
  NavigationStandard_default,
4252
4287
  {
4253
4288
  activatedLanguage,
@@ -4255,9 +4290,10 @@ var NavigationHeader = ({
4255
4290
  menuLinks,
4256
4291
  isOpen: isMenuOpen,
4257
4292
  openButtonRef: menuButtonFocusRef,
4258
- linkComponent: LinkComponent
4293
+ linkComponent: LinkComponent,
4294
+ navigationCloseFocusId
4259
4295
  }
4260
- ),
4296
+ ) }),
4261
4297
  isMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4262
4298
  "div",
4263
4299
  {
@@ -4366,6 +4402,7 @@ var LinkStandard = ({
4366
4402
  target: openTarget,
4367
4403
  rel: openTarget === "_blank" ? "noopener noreferrer" : void 0,
4368
4404
  "aria-label": ariaLabel || void 0,
4405
+ lang: activatedLanguage,
4369
4406
  children: [
4370
4407
  IconComponent && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: `pts-link-icon-circle ${iconClass} ${customClass}`, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(IconComponent, {}) }),
4371
4408
  /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "pts-standard-link-text", children: linkTitle })
@@ -4385,15 +4422,15 @@ var LinkList = ({
4385
4422
  }) => {
4386
4423
  const uniqueId = (0, import_react19.useId)();
4387
4424
  return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "pts-linkList-container", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("ul", { children: linkArray && linkArray.map((link, index) => {
4388
- var _a, _b;
4425
+ var _a, _b, _c;
4389
4426
  return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
4390
4427
  LinkStandard_default,
4391
4428
  {
4392
4429
  url: link.url,
4393
4430
  title: link.title,
4394
- activatedLanguage: activatedLanguage != null ? activatedLanguage : "sv",
4395
- ariaLabel: (_a = link.ariaLabel) != null ? _a : void 0,
4396
- openTarget: (_b = link.openTarget) != null ? _b : "_blank",
4431
+ activatedLanguage: (_a = link.activatedLanguage) != null ? _a : activatedLanguage,
4432
+ ariaLabel: (_b = link.ariaLabel) != null ? _b : void 0,
4433
+ openTarget: (_c = link.openTarget) != null ? _c : "_blank",
4397
4434
  linkComponent: LinkComponent
4398
4435
  }
4399
4436
  ) }, uniqueId + "_" + index);
@@ -4428,7 +4465,7 @@ var Collapse = ({
4428
4465
  "aria-controls": contentId,
4429
4466
  children: [
4430
4467
  `${isOpen ? closeLabel : openLabel} ${title}`,
4431
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "pts-open-close-icon", "aria-hidden": "true", children: isOpen ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CollapseIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ExpandIcon, {}) })
4468
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "pts-collapse-open-close-icon", "aria-hidden": "true", children: isOpen ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CollapseIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ExpandIcon, {}) })
4432
4469
  ]
4433
4470
  }
4434
4471
  ),