@behivetech/organisms.site-header 0.1.2 → 0.1.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A site header with a brand slot, navigation links and optional actions; once the header itself is at least `64rem` wide the links sit inline, and narrower a menu button opens them in a right-hand Drawer.
4
4
 
5
- Docs: https://bht-galaxy.vercel.app/behivetech/organisms/site-header
5
+ Docs: https://platform.behivetech.com/behivetech/organisms/site-header
6
6
 
7
7
  ## Usage
8
8
 
package/dist/index.cjs CHANGED
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,67 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
33
- // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
34
- var require_classnames = __commonJS({
35
- "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
36
- "use strict";
37
- (function() {
38
- "use strict";
39
- var hasOwn = {}.hasOwnProperty;
40
- function classNames() {
41
- var classes = "";
42
- for (var i = 0; i < arguments.length; i++) {
43
- var arg = arguments[i];
44
- if (arg) {
45
- classes = appendClass(classes, parseValue(arg));
46
- }
47
- }
48
- return classes;
49
- }
50
- function parseValue(arg) {
51
- if (typeof arg === "string" || typeof arg === "number") {
52
- return arg;
53
- }
54
- if (typeof arg !== "object") {
55
- return "";
56
- }
57
- if (Array.isArray(arg)) {
58
- return classNames.apply(null, arg);
59
- }
60
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
61
- return arg.toString();
62
- }
63
- var classes = "";
64
- for (var key in arg) {
65
- if (hasOwn.call(arg, key) && arg[key]) {
66
- classes = appendClass(classes, key);
67
- }
68
- }
69
- return classes;
70
- }
71
- function appendClass(value, newClass) {
72
- if (!newClass) {
73
- return value;
74
- }
75
- if (value) {
76
- return value + " " + newClass;
77
- }
78
- return value + newClass;
79
- }
80
- if (typeof module2 !== "undefined" && module2.exports) {
81
- classNames.default = classNames;
82
- module2.exports = classNames;
83
- } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
84
- define("classnames", [], function() {
85
- return classNames;
86
- });
87
- } else {
88
- window.classNames = classNames;
89
- }
90
- })();
91
- }
92
- });
93
-
94
30
  // index.ts
95
31
  var index_exports = {};
96
32
  __export(index_exports, {
@@ -100,48 +36,10 @@ module.exports = __toCommonJS(index_exports);
100
36
 
101
37
  // site-header.tsx
102
38
  var import_react = require("react");
103
-
104
- // ../../../../packages/registry/class-names/dist/index.js
105
- var import_classnames = __toESM(require_classnames(), 1);
106
- var getClassName = ({
107
- className,
108
- modifiers = {},
109
- rootClass,
110
- styles = {}
111
- }) => {
112
- function getModifiers() {
113
- const updatedModifiers = {};
114
- const modifierKeys = Object.keys(modifiers);
115
- if (modifierKeys.length) {
116
- modifierKeys.forEach((modKey) => {
117
- const classKey = `${rootClass}--${modKey}`;
118
- const newClassName = styles[classKey] || classKey;
119
- updatedModifiers[newClassName] = modifiers[modKey] ?? false;
120
- });
121
- }
122
- return updatedModifiers;
123
- }
124
- function getChildClass(childClassName) {
125
- const classKey = `${rootClass}__${childClassName}`;
126
- return styles[classKey] || classKey;
127
- }
128
- function getRootStyles() {
129
- return (0, import_classnames.default)(
130
- className,
131
- {
132
- ...getModifiers()
133
- },
134
- styles[rootClass] || rootClass
135
- );
136
- }
137
- return [getRootStyles(), getChildClass];
138
- };
139
-
140
- // site-header.tsx
39
+ var import_get_class_name = require("@behivetech/get-class-name");
141
40
  var import_atoms = require("@behivetech/atoms.button");
142
- var import_atoms2 = require("@behivetech/atoms.drawer");
143
- var import_atoms3 = require("@behivetech/atoms.icon");
144
- var import_atoms4 = require("@behivetech/atoms.nav-item");
41
+ var import_icons = require("@behivetech/icons.menu");
42
+ var import_atoms2 = require("@behivetech/atoms.nav-item");
145
43
 
146
44
  // site-header.module.scss
147
45
  var site_header_module_default = {
@@ -157,12 +55,19 @@ var site_header_module_default = {
157
55
 
158
56
  // site-header.tsx
159
57
  var import_jsx_runtime = require("react/jsx-runtime");
58
+ var loadDrawer = () => import("@behivetech/atoms.drawer").then((module2) => ({
59
+ default: module2.Drawer
60
+ }));
61
+ var Drawer = (0, import_react.lazy)(loadDrawer);
62
+ var prefetchDrawer = () => {
63
+ loadDrawer().catch(() => void 0);
64
+ };
160
65
  var HeaderLinks = ({
161
66
  links,
162
67
  linkComponent: LinkComponent,
163
68
  onNavigate
164
69
  }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: links.map(({ href, label, current }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
- import_atoms4.NavItem,
70
+ import_atoms2.NavItem,
166
71
  {
167
72
  asChild: true,
168
73
  active: current,
@@ -177,8 +82,8 @@ var MenuDrawer = ({
177
82
  menuLabel,
178
83
  navClassName,
179
84
  onClose
180
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
181
- import_atoms2.Drawer,
85
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
86
+ Drawer,
182
87
  {
183
88
  placement: "right",
184
89
  title: menuLabel,
@@ -194,7 +99,7 @@ var MenuDrawer = ({
194
99
  }
195
100
  ) })
196
101
  }
197
- );
102
+ ) });
198
103
  var useReturnFocus = (isOpen) => {
199
104
  const menuButtonRef = (0, import_react.useRef)(null);
200
105
  (0, import_react.useEffect)(() => {
@@ -206,7 +111,7 @@ var useReturnFocus = (isOpen) => {
206
111
  };
207
112
  var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
208
113
  const [isMenuOpen, setIsMenuOpen] = (0, import_react.useState)(false);
209
- const [, getChildClass] = getClassName({
114
+ const [, getChildClass] = (0, import_get_class_name.getClassName)({
210
115
  rootClass: "BHT__SiteHeader",
211
116
  styles: site_header_module_default
212
117
  });
@@ -222,11 +127,16 @@ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
222
127
  "aria-label": menuLabel,
223
128
  "aria-haspopup": "dialog",
224
129
  "aria-expanded": isMenuOpen,
130
+ onPointerEnter: prefetchDrawer,
131
+ onFocus: prefetchDrawer,
225
132
  onClick: (event) => {
226
- menuButtonRef.current = event.currentTarget;
227
- setIsMenuOpen(true);
133
+ const button = event.currentTarget;
134
+ loadDrawer().then(() => {
135
+ menuButtonRef.current = button;
136
+ setIsMenuOpen(true);
137
+ }).catch(() => void 0);
228
138
  },
229
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_atoms3.MenuIcon, {})
139
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.MenuIcon, {})
230
140
  }
231
141
  ),
232
142
  isMenuOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -250,7 +160,7 @@ var SiteHeader = ({
250
160
  menuLabel,
251
161
  ...rest
252
162
  }) => {
253
- const [rootClass, getChildClass] = getClassName({
163
+ const [rootClass, getChildClass] = (0, import_get_class_name.getClassName)({
254
164
  className,
255
165
  rootClass: "BHT__SiteHeader",
256
166
  styles: site_header_module_default
@@ -275,12 +185,3 @@ var SiteHeader = ({
275
185
  0 && (module.exports = {
276
186
  SiteHeader
277
187
  });
278
- /*! Bundled license information:
279
-
280
- classnames/index.js:
281
- (*!
282
- Copyright (c) 2018 Jed Watson.
283
- Licensed under the MIT License (MIT), see
284
- http://jedwatson.github.io/classnames
285
- *)
286
- */
package/dist/index.js CHANGED
@@ -1,137 +1,14 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
28
- var require_classnames = __commonJS({
29
- "../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
30
- "use strict";
31
- (function() {
32
- "use strict";
33
- var hasOwn = {}.hasOwnProperty;
34
- function classNames() {
35
- var classes = "";
36
- for (var i = 0; i < arguments.length; i++) {
37
- var arg = arguments[i];
38
- if (arg) {
39
- classes = appendClass(classes, parseValue(arg));
40
- }
41
- }
42
- return classes;
43
- }
44
- function parseValue(arg) {
45
- if (typeof arg === "string" || typeof arg === "number") {
46
- return arg;
47
- }
48
- if (typeof arg !== "object") {
49
- return "";
50
- }
51
- if (Array.isArray(arg)) {
52
- return classNames.apply(null, arg);
53
- }
54
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
55
- return arg.toString();
56
- }
57
- var classes = "";
58
- for (var key in arg) {
59
- if (hasOwn.call(arg, key) && arg[key]) {
60
- classes = appendClass(classes, key);
61
- }
62
- }
63
- return classes;
64
- }
65
- function appendClass(value, newClass) {
66
- if (!newClass) {
67
- return value;
68
- }
69
- if (value) {
70
- return value + " " + newClass;
71
- }
72
- return value + newClass;
73
- }
74
- if (typeof module !== "undefined" && module.exports) {
75
- classNames.default = classNames;
76
- module.exports = classNames;
77
- } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
78
- define("classnames", [], function() {
79
- return classNames;
80
- });
81
- } else {
82
- window.classNames = classNames;
83
- }
84
- })();
85
- }
86
- });
87
-
88
1
  // site-header.tsx
89
2
  import {
3
+ Suspense,
4
+ lazy,
90
5
  useEffect,
91
6
  useRef,
92
7
  useState
93
8
  } from "react";
94
-
95
- // ../../../../packages/registry/class-names/dist/index.js
96
- var import_classnames = __toESM(require_classnames(), 1);
97
- var getClassName = ({
98
- className,
99
- modifiers = {},
100
- rootClass,
101
- styles = {}
102
- }) => {
103
- function getModifiers() {
104
- const updatedModifiers = {};
105
- const modifierKeys = Object.keys(modifiers);
106
- if (modifierKeys.length) {
107
- modifierKeys.forEach((modKey) => {
108
- const classKey = `${rootClass}--${modKey}`;
109
- const newClassName = styles[classKey] || classKey;
110
- updatedModifiers[newClassName] = modifiers[modKey] ?? false;
111
- });
112
- }
113
- return updatedModifiers;
114
- }
115
- function getChildClass(childClassName) {
116
- const classKey = `${rootClass}__${childClassName}`;
117
- return styles[classKey] || classKey;
118
- }
119
- function getRootStyles() {
120
- return (0, import_classnames.default)(
121
- className,
122
- {
123
- ...getModifiers()
124
- },
125
- styles[rootClass] || rootClass
126
- );
127
- }
128
- return [getRootStyles(), getChildClass];
129
- };
130
-
131
- // site-header.tsx
9
+ import { getClassName } from "@behivetech/get-class-name";
132
10
  import { Button } from "@behivetech/atoms.button";
133
- import { Drawer } from "@behivetech/atoms.drawer";
134
- import { MenuIcon } from "@behivetech/atoms.icon";
11
+ import { MenuIcon } from "@behivetech/icons.menu";
135
12
  import { NavItem } from "@behivetech/atoms.nav-item";
136
13
 
137
14
  // site-header.module.scss
@@ -148,6 +25,13 @@ var site_header_module_default = {
148
25
 
149
26
  // site-header.tsx
150
27
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
28
+ var loadDrawer = () => import("@behivetech/atoms.drawer").then((module) => ({
29
+ default: module.Drawer
30
+ }));
31
+ var Drawer = lazy(loadDrawer);
32
+ var prefetchDrawer = () => {
33
+ loadDrawer().catch(() => void 0);
34
+ };
151
35
  var HeaderLinks = ({
152
36
  links,
153
37
  linkComponent: LinkComponent,
@@ -168,7 +52,7 @@ var MenuDrawer = ({
168
52
  menuLabel,
169
53
  navClassName,
170
54
  onClose
171
- }) => /* @__PURE__ */ jsx(
55
+ }) => /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
172
56
  Drawer,
173
57
  {
174
58
  placement: "right",
@@ -185,7 +69,7 @@ var MenuDrawer = ({
185
69
  }
186
70
  ) })
187
71
  }
188
- );
72
+ ) });
189
73
  var useReturnFocus = (isOpen) => {
190
74
  const menuButtonRef = useRef(null);
191
75
  useEffect(() => {
@@ -213,9 +97,14 @@ var HeaderMenu = ({ links, linkComponent, menuLabel }) => {
213
97
  "aria-label": menuLabel,
214
98
  "aria-haspopup": "dialog",
215
99
  "aria-expanded": isMenuOpen,
100
+ onPointerEnter: prefetchDrawer,
101
+ onFocus: prefetchDrawer,
216
102
  onClick: (event) => {
217
- menuButtonRef.current = event.currentTarget;
218
- setIsMenuOpen(true);
103
+ const button = event.currentTarget;
104
+ loadDrawer().then(() => {
105
+ menuButtonRef.current = button;
106
+ setIsMenuOpen(true);
107
+ }).catch(() => void 0);
219
108
  },
220
109
  children: /* @__PURE__ */ jsx(MenuIcon, {})
221
110
  }
@@ -265,12 +154,3 @@ var SiteHeader = ({
265
154
  export {
266
155
  SiteHeader
267
156
  };
268
- /*! Bundled license information:
269
-
270
- classnames/index.js:
271
- (*!
272
- Copyright (c) 2018 Jed Watson.
273
- Licensed under the MIT License (MIT), see
274
- http://jedwatson.github.io/classnames
275
- *)
276
- */
package/docs.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
3
+ "version": 2,
4
+ "generatedAt": "2026-11-11T04:42:40.853Z",
5
+ "docs": [
6
+ {
7
+ "displayName": "SiteHeader",
8
+ "description": "Site header with a brand slot, navigation links and optional actions. While\nthe header is at least `64rem` wide the links sit inline; narrower, a menu\nbutton opens them in a right-hand `Drawer`, which keeps the links in reach of\none thumb on a phone. The switch follows the header's own width (a container\nquery), not the viewport.",
9
+ "extendsNative": true,
10
+ "props": [
11
+ {
12
+ "name": "brand",
13
+ "type": "ReactNode",
14
+ "required": true,
15
+ "defaultValue": null,
16
+ "description": "Brand slot at the start of the bar; rendered as given, so pass your own home link"
17
+ },
18
+ {
19
+ "name": "links",
20
+ "type": "SiteHeaderLink[]",
21
+ "required": true,
22
+ "defaultValue": null,
23
+ "description": "Navigation links: inline once the header itself is at least `64rem` wide (a container query), in a Drawer when narrower"
24
+ },
25
+ {
26
+ "name": "menuLabel",
27
+ "type": "string",
28
+ "required": true,
29
+ "defaultValue": null,
30
+ "description": "Accessible name of the menu button, the navigation landmarks and the Drawer title, already translated"
31
+ },
32
+ {
33
+ "name": "actions",
34
+ "type": "ReactNode",
35
+ "required": false,
36
+ "defaultValue": null,
37
+ "description": "Optional actions that stay in the bar at every breakpoint, e.g. a booking button"
38
+ },
39
+ {
40
+ "name": "className",
41
+ "type": "string",
42
+ "required": false,
43
+ "defaultValue": null,
44
+ "description": "Additional class names to merge with the component root element"
45
+ },
46
+ {
47
+ "name": "linkComponent",
48
+ "type": "ElementType<SiteHeaderLinkProps>",
49
+ "required": false,
50
+ "defaultValue": "a",
51
+ "description": "Component that renders each link, so a router link such as Next's `Link`\ncan be injected. Receives `href`, `children` and the item's props. Defaults to `a`."
52
+ }
53
+ ]
54
+ }
55
+ ],
56
+ "functions": []
57
+ }
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@behivetech/organisms.site-header",
3
- "version": "0.1.2",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "description": "A site header with a brand slot, navigation links and optional actions; once the header itself is at least `64rem` wide the links sit inline, and narrower a menu button opens them in a right-hand Drawer.",
6
6
  "type": "module",
7
7
  "private": false,
8
+ "sideEffects": [
9
+ "**/*.css"
10
+ ],
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -32,37 +35,38 @@
32
35
  }
33
36
  ]
34
37
  },
38
+ "dependencies": {
39
+ "@behivetech/atoms.button": "0.5.2",
40
+ "@behivetech/atoms.drawer": "0.4.10",
41
+ "@behivetech/icons.base": "0.4.0",
42
+ "@behivetech/atoms.nav-item": "0.5.2",
43
+ "@behivetech/cms.base-styles": "0.5.1",
44
+ "@behivetech/get-class-name": "0.1.0",
45
+ "@behivetech/icons.menu": "0.1.0"
46
+ },
35
47
  "peerDependencies": {
36
48
  "react": "^19.2.7",
37
49
  "react-dom": "^19.2.7"
38
50
  },
39
51
  "devDependencies": {
52
+ "@bht-component-registry/env": "0.1.0",
40
53
  "@types/react": "19.2.17",
41
54
  "@types/react-dom": "19.2.3",
42
55
  "eslint": "^9.39.5",
43
56
  "tsup": "^8.5.1",
44
57
  "typescript": "^6.0.3",
45
- "vitest": "^4.1.10",
46
- "@behivetech/cms.base-styles": "0.4.0",
47
- "@bht-component-registry/class-names": "0.0.6",
48
- "@bht-component-registry/env": "0.1.0"
58
+ "vitest": "^4.1.10"
49
59
  },
50
60
  "repository": {
51
61
  "type": "git",
52
62
  "url": "https://github.com/behivetech/bht-galaxy.git",
53
63
  "directory": "registry/behivetech/organisms/site-header"
54
64
  },
55
- "homepage": "https://bht-galaxy.vercel.app/behivetech/organisms/site-header",
65
+ "homepage": "https://platform.behivetech.com/behivetech/organisms/site-header",
56
66
  "publishConfig": {
57
- "registry": "https://registry.npmjs.org",
67
+ "registry": "https://npm.pkg.github.com",
58
68
  "access": "public"
59
69
  },
60
- "dependencies": {
61
- "@behivetech/atoms.button": "0.5.0",
62
- "@behivetech/atoms.icon": "0.3.6",
63
- "@behivetech/atoms.drawer": "0.4.6",
64
- "@behivetech/atoms.nav-item": "0.5.0"
65
- },
66
70
  "scripts": {
67
71
  "build": "tsup && bht-registry-docgen",
68
72
  "dev": "tsup --watch",
package/site-header.tsx CHANGED
@@ -3,17 +3,35 @@ import {
3
3
  type ElementType,
4
4
  type HTMLAttributes,
5
5
  type ReactNode,
6
+ Suspense,
7
+ lazy,
6
8
  useEffect,
7
9
  useRef,
8
10
  useState,
9
11
  } from "react";
10
- import { getClassName } from "@bht-component-registry/class-names";
12
+ import { getClassName } from "@behivetech/get-class-name";
11
13
  import { Button } from "@behivetech/atoms.button";
12
- import { Drawer } from "@behivetech/atoms.drawer";
13
- import { MenuIcon } from "@behivetech/atoms.icon";
14
+ import { MenuIcon } from "@behivetech/icons.menu";
14
15
  import { NavItem } from "@behivetech/atoms.nav-item";
15
16
  import styles from "./site-header.module.scss";
16
17
 
18
+ /** Loads the Drawer module; repeat calls share the one request. */
19
+ const loadDrawer = () =>
20
+ import("@behivetech/atoms.drawer").then((module) => ({
21
+ default: module.Drawer,
22
+ }));
23
+
24
+ // The Drawer (Radix Dialog and its focus handling) is about 10 KB gzipped and
25
+ // opens only after a tap at phone width, so it is fetched on demand: ahead of
26
+ // the tap when the reader's pointer or focus reaches the menu button, and at
27
+ // the latest when the button is pressed.
28
+ const Drawer = lazy(loadDrawer);
29
+
30
+ /** Starts the request ahead of the tap; a failure here is retried by the tap itself. */
31
+ const prefetchDrawer = () => {
32
+ loadDrawer().catch(() => undefined);
33
+ };
34
+
17
35
  /** One navigation link of the header. */
18
36
  export interface SiteHeaderLink {
19
37
  /** Destination of the link */
@@ -84,7 +102,7 @@ interface MenuDrawerProps {
84
102
  onClose: () => void;
85
103
  }
86
104
 
87
- /** The Drawer that holds the links while the header is narrow. */
105
+ /** The Drawer that holds the links while the header is narrow; nothing shows while its code loads. */
88
106
  const MenuDrawer = ({
89
107
  links,
90
108
  linkComponent,
@@ -92,21 +110,23 @@ const MenuDrawer = ({
92
110
  navClassName,
93
111
  onClose,
94
112
  }: MenuDrawerProps) => (
95
- <Drawer
96
- placement="right"
97
- title={menuLabel}
98
- headingLevel={2}
99
- padding="sm"
100
- onClose={onClose}
101
- >
102
- <nav aria-label={menuLabel} className={navClassName}>
103
- <HeaderLinks
104
- links={links}
105
- linkComponent={linkComponent}
106
- onNavigate={onClose}
107
- />
108
- </nav>
109
- </Drawer>
113
+ <Suspense fallback={null}>
114
+ <Drawer
115
+ placement="right"
116
+ title={menuLabel}
117
+ headingLevel={2}
118
+ padding="sm"
119
+ onClose={onClose}
120
+ >
121
+ <nav aria-label={menuLabel} className={navClassName}>
122
+ <HeaderLinks
123
+ links={links}
124
+ linkComponent={linkComponent}
125
+ onNavigate={onClose}
126
+ />
127
+ </nav>
128
+ </Drawer>
129
+ </Suspense>
110
130
  );
111
131
 
112
132
  interface HeaderMenuProps {
@@ -152,9 +172,21 @@ const HeaderMenu = ({ links, linkComponent, menuLabel }: HeaderMenuProps) => {
152
172
  aria-label={menuLabel}
153
173
  aria-haspopup="dialog"
154
174
  aria-expanded={isMenuOpen}
175
+ onPointerEnter={prefetchDrawer}
176
+ onFocus={prefetchDrawer}
155
177
  onClick={(event) => {
156
- menuButtonRef.current = event.currentTarget;
157
- setIsMenuOpen(true);
178
+ const button = event.currentTarget;
179
+
180
+ // The menu counts as open (and `aria-expanded` turns true) only once
181
+ // the Drawer's code is here, so assistive technology is never told
182
+ // about a dialog that is not there yet. A failed request leaves the
183
+ // menu closed, and the next tap asks again.
184
+ loadDrawer()
185
+ .then(() => {
186
+ menuButtonRef.current = button;
187
+ setIsMenuOpen(true);
188
+ })
189
+ .catch(() => undefined);
158
190
  }}
159
191
  >
160
192
  <MenuIcon />