|
4 | 4 | import { t } from "$lib/stores/locale.store"; |
5 | 5 | import { nonNullish } from "@dfinity/utils"; |
6 | 6 |
|
7 | | - const handleKeyDownInput = ( |
8 | | - event: KeyboardEvent, |
9 | | - currentTabIndex: number, |
10 | | - ) => { |
| 7 | + let inputContainerRef: HTMLDivElement | null = null; |
| 8 | +
|
| 9 | + const handleKeyDownInput = (event: KeyboardEvent, currentIndex: number) => { |
11 | 10 | if (event.key === "Enter" || event.key === " ") { |
12 | 11 | event.preventDefault(); |
13 | | - const nextTabIndex = currentTabIndex + 1; |
14 | | - const nextElement = document.querySelector( |
15 | | - `[tabindex="${nextTabIndex}"]`, |
16 | | - ) as HTMLElement; |
| 12 | + const nextTabIndex = currentIndex + 1; |
| 13 | + const inputElements = inputContainerRef?.querySelectorAll( |
| 14 | + "input", |
| 15 | + ) as NodeListOf<HTMLInputElement>; |
| 16 | + const nextElement = inputElements?.[nextTabIndex]; |
17 | 17 | if (nonNullish(nextElement)) { |
18 | 18 | nextElement.focus(); |
19 | 19 | } |
|
36 | 36 | </p> |
37 | 37 | </div> |
38 | 38 | <div class="flex flex-col gap-3"> |
39 | | - <div class="grid grid-cols-3 gap-3"> |
| 39 | + <div class="grid grid-cols-3 gap-3" bind:this={inputContainerRef}> |
40 | 40 | {#each Array.from({ length: 24 }) as _, i} |
41 | 41 | <label class="relative h-8"> |
42 | 42 | <!-- Text input --> |
43 | 43 | <input |
44 | 44 | type="text" |
45 | 45 | id={`recovery-phrase-${i}`} |
46 | | - tabindex={i + 1} |
47 | | - on:keydown={(e) => handleKeyDownInput(e, i + 1)} |
| 46 | + on:keydown={(e) => handleKeyDownInput(e, i)} |
48 | 47 | class="peer text-text-primary ring-border-secondary focus:ring-border-brand h-8 w-full rounded-full border-none bg-transparent pl-10 text-base ring outline-none ring-inset focus:ring-2" |
49 | 48 | /> |
50 | 49 | <!-- Left slot --> |
|
58 | 57 | {/each} |
59 | 58 | </div> |
60 | 59 | <div class="flex flex-row gap-2"> |
61 | | - <Button class="w-full" variant="tertiary" tabindex={25} |
62 | | - >{$t`Show all`}</Button |
63 | | - > |
64 | | - <Button class="w-full" variant="tertiary" tabindex={26} |
65 | | - >{$t`Clear all`}</Button |
66 | | - > |
| 60 | + <Button class="w-full" variant="tertiary">{$t`Show all`}</Button> |
| 61 | + <Button class="w-full" variant="tertiary">{$t`Clear all`}</Button> |
67 | 62 | </div> |
68 | 63 | </div> |
69 | | - <Button size="xl" variant="secondary" tabindex={27}>{$t`Cancel`}</Button> |
| 64 | + <Button size="xl" variant="secondary">{$t`Cancel`}</Button> |
70 | 65 | </div> |
71 | 66 | </AuthPanel> |
72 | 67 | </div> |
|
0 commit comments