|
1 | 1 | <script lang="ts">
|
2 | 2 | import { afterNavigate } from '$app/navigation';
|
3 | 3 | import { page } from '$app/stores';
|
4 |
| - import { trap } from '@sveltejs/site-kit/actions'; |
| 4 | + import { focusable_children, trap } from '@sveltejs/site-kit/actions'; |
5 | 5 | import { Icon } from '@sveltejs/site-kit/components';
|
6 | 6 | import type { Snippet } from 'svelte';
|
7 | 7 |
|
|
22 | 22 | }}
|
23 | 23 | />
|
24 | 24 |
|
| 25 | +<!-- svelte-ignore a11y_no_noninteractive_element_interactions --> |
25 | 26 | <details
|
26 | 27 | class="examples-select"
|
27 | 28 | bind:open
|
|
35 | 36 | details.scrollIntoView();
|
36 | 37 | }}
|
37 | 38 | ontoggle={(e) => {
|
38 |
| - const details = e.currentTarget; |
39 |
| - if (!details.open) return; |
| 39 | + const details = e.currentTarget; |
| 40 | + if (!details.open) return; |
40 | 41 |
|
41 |
| - // close all details elements... |
42 |
| - for (const child of details.querySelectorAll('details[open]')) { |
43 |
| - (child as HTMLDetailsElement).open = false; |
44 |
| - } |
| 42 | + // close all details elements... |
| 43 | + for (const child of details.querySelectorAll('details[open]')) { |
| 44 | + (child as HTMLDetailsElement).open = false; |
| 45 | + } |
45 | 46 |
|
46 |
| - // except parents of the current one |
47 |
| - const current = details.querySelector(`[href="${$page.url.pathname}"]`) as HTMLAnchorElement | null; |
48 |
| - if (!current) return; |
| 47 | + // except parents of the current one |
| 48 | + const current = details.querySelector(`[href="${$page.url.pathname}"]`) as HTMLAnchorElement | null; |
| 49 | + if (!current) return; |
49 | 50 |
|
50 |
| - let node = current as Element; |
| 51 | + let node = current as Element; |
51 | 52 |
|
52 |
| - while ((node = (node.parentNode) as Element) && node !== details) { |
53 |
| - if (node.nodeName === 'DETAILS') { |
54 |
| - (node as HTMLDetailsElement).open = true; |
| 53 | + while ((node = (node.parentNode) as Element) && node !== details) { |
| 54 | + if (node.nodeName === 'DETAILS') { |
| 55 | + (node as HTMLDetailsElement).open = true; |
| 56 | + } |
55 | 57 | }
|
56 |
| - } |
57 | 58 |
|
58 |
| - current.scrollIntoView(); |
59 |
| - current.focus(); |
60 |
| -}} |
| 59 | + current.scrollIntoView(); |
| 60 | + current.focus(); |
| 61 | + }} |
| 62 | + onkeydown={(e) => { |
| 63 | + if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { |
| 64 | + const children = focusable_children(e.currentTarget); |
| 65 | + |
| 66 | + if (e.key === 'ArrowDown') { |
| 67 | + children.next(); |
| 68 | + } else { |
| 69 | + children.prev(); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + if (document.activeElement?.nodeName === 'SUMMARY' && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) { |
| 74 | + (document.activeElement.parentNode as HTMLDetailsElement).open = e.key === 'ArrowRight'; |
| 75 | + } |
| 76 | + }} |
61 | 77 | >
|
62 | 78 | <summary class="raised icon" aria-label={label}><Icon name="menu" /></summary>
|
63 | 79 |
|
|
0 commit comments