File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ const filteredHeadings = $derived(
18
18
? headings .filter ((heading ) => heading .text .toLowerCase ().includes (searchTrimLower ))
19
19
: headings
20
20
)
21
+
22
+ function handleKeydown(event : KeyboardEvent ) {
23
+ if (event .key === ' Enter' ) {
24
+ event .preventDefault ()
25
+ const firstHeading = filteredHeadings [0 ]
26
+ if (firstHeading ) {
27
+ window .location .hash = firstHeading .slug
28
+
29
+ const input = event .currentTarget as HTMLInputElement
30
+ input .focus ()
31
+ }
32
+ }
33
+ }
21
34
</script >
22
35
23
36
<div class =" outline" >
@@ -27,7 +40,7 @@ const filteredHeadings = $derived(
27
40
28
41
{#if enableSearch }
29
42
<!-- svelte-ignore a11y_autofocus -->
30
- <input bind:value ={search } placeholder =" Search..." class =" search" autofocus />
43
+ <input bind:value ={search } placeholder ="Search..." class ="search" autofocus onkeydown ={ handleKeydown } />
31
44
{/if }
32
45
33
46
<ul >
You can’t perform that action at this time.
0 commit comments