@onsvisual/svelte-components 0.1.79 → 0.1.81
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/@types/index.d.ts +1 -0
- package/dist/@types/inputs/Input/Input.svelte.d.ts +2 -2
- package/dist/@types/wrappers/Main/Main.svelte.d.ts +2 -0
- package/dist/css/main.css +2 -2
- package/dist/index.js +1 -0
- package/dist/layout/Header/Header.svelte +132 -5
- package/dist/layout/SkipLink/SkipLink.svelte +1 -1
- package/dist/wrappers/Main/Main.svelte +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export { default as NavSection } from "./layout/NavSections/NavSection.svelte";
|
|
|
27
27
|
export { default as NavSections } from "./layout/NavSections/NavSections.svelte";
|
|
28
28
|
export { default as Notice } from "./layout/Notice/Notice.svelte";
|
|
29
29
|
export { default as PhaseBanner } from "./layout/PhaseBanner/PhaseBanner.svelte";
|
|
30
|
+
export { default as RelatedContent } from "./layout/RelatedContent/RelatedContent.svelte";
|
|
30
31
|
export { default as Scroller } from "./layout/Scroller/Scroller.svelte";
|
|
31
32
|
export { default as ScrollerSection } from "./layout/Scroller/ScrollerSection.svelte";
|
|
32
33
|
export { default as Section } from "./layout/Section/Section.svelte";
|
|
@@ -58,7 +58,21 @@
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
$: setPaths(mounted, $page);
|
|
61
|
-
onMount(() =>
|
|
61
|
+
onMount(() => {
|
|
62
|
+
mounted = true;
|
|
63
|
+
|
|
64
|
+
/// Add keyboard event listeners
|
|
65
|
+
const navItems = document.querySelectorAll(".js-nav");
|
|
66
|
+
navItems.forEach((item) => {
|
|
67
|
+
item.addEventListener("keydown", handleKeydown);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return () => {
|
|
71
|
+
navItems.forEach((item) => {
|
|
72
|
+
item.removeEventListener("keydown", handleKeydown);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
});
|
|
62
76
|
|
|
63
77
|
let menuExpanded = false;
|
|
64
78
|
let searchExpanded = false;
|
|
@@ -273,6 +287,111 @@
|
|
|
273
287
|
menu[i].expanded = !menu[i].expanded;
|
|
274
288
|
}
|
|
275
289
|
}
|
|
290
|
+
|
|
291
|
+
function handleKeydown(event) {
|
|
292
|
+
const target = event.currentTarget;
|
|
293
|
+
// Find the currently focused expandable child link within the navigation item
|
|
294
|
+
const focusedExpandableChild = target.querySelector(".js-expandable__child a:focus");
|
|
295
|
+
|
|
296
|
+
// Find all child links in the current navigation item
|
|
297
|
+
const childLinks = Array.from(target.querySelectorAll(".js-expandable__child a"));
|
|
298
|
+
|
|
299
|
+
// Close any expanded items from mouse events
|
|
300
|
+
const allExpandedItems = document.querySelectorAll(".js-expandable-active");
|
|
301
|
+
allExpandedItems.forEach((item) => {
|
|
302
|
+
if (item !== target) {
|
|
303
|
+
item.classList.remove("js-expandable-active");
|
|
304
|
+
const content = item.querySelector(".js-expandable__content");
|
|
305
|
+
if (content) {
|
|
306
|
+
content.classList.add("js-nav-hidden");
|
|
307
|
+
content.setAttribute("aria-expanded", "false");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
switch (event.key) {
|
|
313
|
+
case "Tab":
|
|
314
|
+
if (focusedExpandableChild) {
|
|
315
|
+
target.classList.remove("primary-nav__item--focus");
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
|
|
319
|
+
case "Escape":
|
|
320
|
+
event.preventDefault();
|
|
321
|
+
target.classList.remove("primary-nav__item--focus");
|
|
322
|
+
const firstNavLink = target.closest(".js-nav").querySelector("a:first-child");
|
|
323
|
+
if (firstNavLink) {
|
|
324
|
+
firstNavLink.classList.add("hide-children");
|
|
325
|
+
firstNavLink.focus();
|
|
326
|
+
firstNavLink.addEventListener(
|
|
327
|
+
"focusout",
|
|
328
|
+
() => {
|
|
329
|
+
firstNavLink.classList.remove("hide-children");
|
|
330
|
+
},
|
|
331
|
+
{ once: true }
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
break;
|
|
335
|
+
|
|
336
|
+
case "ArrowDown":
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
if (!focusedExpandableChild) {
|
|
339
|
+
// If no child is focused, focus the first child. Needs to start from 0 as first child is link to primary nav.
|
|
340
|
+
const firstChild = childLinks[1];
|
|
341
|
+
if (firstChild) {
|
|
342
|
+
console.log("add focus");
|
|
343
|
+
target.classList.add("primary-nav__item--focus");
|
|
344
|
+
firstChild.focus({ focusVisible: true });
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
// Find the current index and move to the next child
|
|
348
|
+
const currentIndex = childLinks.indexOf(focusedExpandableChild);
|
|
349
|
+
if (currentIndex < childLinks.length - 1) {
|
|
350
|
+
childLinks[currentIndex + 1].focus();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
|
|
355
|
+
case "ArrowUp":
|
|
356
|
+
event.preventDefault();
|
|
357
|
+
|
|
358
|
+
if (focusedExpandableChild) {
|
|
359
|
+
const currentIndex = childLinks.indexOf(focusedExpandableChild);
|
|
360
|
+
if (currentIndex > 0) {
|
|
361
|
+
// Move to previous child
|
|
362
|
+
childLinks[currentIndex - 1].focus();
|
|
363
|
+
} else {
|
|
364
|
+
// If at first child, move focus back to main nav link
|
|
365
|
+
target.classList.remove("primary-nav__item--focus");
|
|
366
|
+
const mainLink = target.querySelector("a:first-child");
|
|
367
|
+
if (mainLink) {
|
|
368
|
+
mainLink.focus();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
|
|
374
|
+
case "ArrowRight":
|
|
375
|
+
event.preventDefault();
|
|
376
|
+
target.classList.remove("primary-nav__item--focus");
|
|
377
|
+
const nextNav = target.closest(".js-nav").nextElementSibling;
|
|
378
|
+
if (nextNav) {
|
|
379
|
+
const firstLink = nextNav.querySelector("a:first-child");
|
|
380
|
+
if (firstLink) firstLink.focus();
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
|
|
384
|
+
case "ArrowLeft":
|
|
385
|
+
event.preventDefault();
|
|
386
|
+
target.classList.remove("primary-nav__item--focus");
|
|
387
|
+
const prevNav = target.closest(".js-nav").previousElementSibling;
|
|
388
|
+
if (prevNav) {
|
|
389
|
+
const firstLink = prevNav.querySelector("a:first-child");
|
|
390
|
+
if (firstLink) firstLink.focus();
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
276
395
|
</script>
|
|
277
396
|
|
|
278
397
|
<header class="ons-header" role="banner">
|
|
@@ -340,6 +459,7 @@
|
|
|
340
459
|
</div>
|
|
341
460
|
</div>
|
|
342
461
|
<div class="primary-nav print--hide">
|
|
462
|
+
<!-- Controls -->
|
|
343
463
|
<nav aria-label="Header links">
|
|
344
464
|
<ul class="nav--controls">
|
|
345
465
|
<li class="nav--controls__item" class:menu-is-expanded="{menuExpanded}">
|
|
@@ -375,12 +495,15 @@
|
|
|
375
495
|
</a>
|
|
376
496
|
</li>
|
|
377
497
|
</ul>
|
|
498
|
+
|
|
499
|
+
<!-- Main Navigation -->
|
|
378
500
|
<ul
|
|
379
501
|
class="wrapper primary-nav__list"
|
|
380
502
|
class:nav-main--hidden="{!menuExpanded}"
|
|
381
503
|
id="nav-primary"
|
|
382
504
|
aria-expanded="{menuExpanded}"
|
|
383
505
|
>
|
|
506
|
+
<!-- Home Link -->
|
|
384
507
|
<li class="primary-nav__item js-nav">
|
|
385
508
|
<a
|
|
386
509
|
class="primary-nav__link col col--md-7 col--lg-9"
|
|
@@ -388,6 +511,8 @@
|
|
|
388
511
|
style="color: #e5e6e7">{i18n("Home")}</a
|
|
389
512
|
>
|
|
390
513
|
</li>
|
|
514
|
+
|
|
515
|
+
<!-- Menu Items -->
|
|
391
516
|
{#each [...menu
|
|
392
517
|
.filter((d) => d.children)
|
|
393
518
|
.sort( (a, b) => a["label_" + lang].localeCompare(b["label_" + lang]) ), ...menu.filter((d) => !d.children)] as item, i}
|
|
@@ -405,7 +530,7 @@
|
|
|
405
530
|
>
|
|
406
531
|
<span aria-hidden="true" class="expansion-indicator"></span>
|
|
407
532
|
<span class="submenu-title">
|
|
408
|
-
{item[
|
|
533
|
+
{item[`label_${lang}`]}
|
|
409
534
|
</span>
|
|
410
535
|
</a>
|
|
411
536
|
<ul
|
|
@@ -416,15 +541,15 @@
|
|
|
416
541
|
>
|
|
417
542
|
<li class="primary-nav__child-item js-expandable__child hide--md">
|
|
418
543
|
<a class="primary-nav__child-link" tabindex="-1" href="{baseurl}{item.url}"
|
|
419
|
-
>{item[
|
|
544
|
+
>{item[`label_${lang}`]}</a
|
|
420
545
|
>
|
|
421
546
|
</li>
|
|
422
|
-
{#each [...item.children].sort( (a, b) => a[
|
|
547
|
+
{#each [...item.children].sort( (a, b) => a[`label_${lang}`].localeCompare(b[`label_${lang}`]) ) as child}
|
|
423
548
|
<li class="primary-nav__child-item js-expandable__child">
|
|
424
549
|
<a
|
|
425
550
|
class="primary-nav__child-link"
|
|
426
551
|
tabindex="-1"
|
|
427
|
-
href="{baseurl}{child.url}">{child[
|
|
552
|
+
href="{baseurl}{child.url}">{child[`label_${lang}`]}</a
|
|
428
553
|
>
|
|
429
554
|
</li>
|
|
430
555
|
{/each}
|
|
@@ -441,6 +566,8 @@
|
|
|
441
566
|
</li>
|
|
442
567
|
{/if}
|
|
443
568
|
{/each}
|
|
569
|
+
|
|
570
|
+
<!-- Language Switcher -->
|
|
444
571
|
<li class="hide--md primary-nav__language">
|
|
445
572
|
{#if lang == "en"}
|
|
446
573
|
<span>English (EN) | </span>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onsvisual/svelte-components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.81",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://onsvisual.github.io/svelte-components",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@babel/eslint-plugin": "^7.19.1",
|
|
34
34
|
"@babel/preset-env": "^7.21.4",
|
|
35
35
|
"@evilmartians/lefthook": "^1.3.10",
|
|
36
|
-
"@onsvisual/svelte-charts": "^0.3.
|
|
36
|
+
"@onsvisual/svelte-charts": "^0.3.18",
|
|
37
37
|
"@reuters-graphics/eslint-config": "^0.0.2",
|
|
38
38
|
"@storybook/addon-actions": "^7.0.20",
|
|
39
39
|
"@storybook/addon-docs": "^7.0.20",
|