Skip to content

Commit 96c3473

Browse files
committed
feat: pressing "Enter" in the outline on the Function reference page scrolls to the first filtered item
1 parent f51c444 commit 96c3473

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/Outline.svelte

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ const filteredHeadings = $derived(
1818
? headings.filter((heading) => heading.text.toLowerCase().includes(searchTrimLower))
1919
: headings
2020
)
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+
}
2134
</script>
2235

2336
<div class="outline">
@@ -27,7 +40,7 @@ const filteredHeadings = $derived(
2740

2841
{#if enableSearch}
2942
<!-- 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} />
3144
{/if}
3245

3346
<ul>

0 commit comments

Comments
 (0)