Page·Free
FAQ with search (Svelte)
A FAQ section for Svelte 5 in TypeScript. The search box filters questions as you type, and two buttons open or close all the answers. It is built on details elements, so keyboard and screen reader support comes from the browser.
Free to install.
If PocketCode is installed on your Android device, this opens the page in the app.
Preview
FaqPage.svelte · 181 lines
<!--
FAQ page for Svelte 5 (runes + TypeScript), with no libraries. A search box filters the
questions as you type, every answer opens and closes on its own (native <details>, so it
works with the keyboard and screen readers), and two buttons open or close them all.
<FaqPage title="Help" items={[{ question: 'Is it free?', answer: 'Yes, the basic plan is.' }]} />
Colours come from CSS variables with fallbacks: --faq-text, --faq-muted, --faq-border.
-->
<script lang="ts">
export interface FaqItem {
question: string;
answer: string;
}
interface Props {
title?: string;
items?: FaqItem[];
}
let {
title = 'Frequently asked questions',
items = [
{ question: 'How do I reset my password?', answer: 'Open Settings, then Account, and choose Reset password. We send a link to your email.' },
{ question: 'Can I use it offline?', answer: 'Yes. Your files stay on the device and sync the next time you are online.' },
{ question: 'How do I delete my account?', answer: 'Open Settings, then Account, and choose Delete account. This removes your data from our servers.' },
],
}: Props = $props();
const uid = $props.id();
let query = $state('');
let open = $state<boolean[]>([]);
const words = $derived(query.toLowerCase().split(/\s+/).filter(Boolean));
const visible = $derived(
items
.map((item, index) => ({ item, index }))
.filter(({ item }) => {
const text = `${item.question} ${item.answer}`.toLowerCase();
return words.every((word) => text.includes(word));
}),
);
function setAll(value: boolean) {
open = items.map(() => value);
}
</script>
<section class="faq" aria-labelledby="{uid}-title">
<h2 id="{uid}-title">{title}</h2>
<div class="tools">
<label for="{uid}-search">Search the questions</label>
<input id="{uid}-search" type="search" bind:value={query} autocomplete="off" />
<div class="all">
<button type="button" onclick={() => setAll(true)}>Open all</button>
<button type="button" onclick={() => setAll(false)}>Close all</button>
</div>
</div>
<p class="count" role="status">
{#if words.length}
{visible.length} of {items.length} {items.length === 1 ? 'question' : 'questions'}
{/if}
</p>
{#each visible as { item, index } (index)}
<details bind:open={open[index]}>
<summary>{item.question}</summary>
<p>{item.answer}</p>
</details>
{:else}
<p class="empty">No questions match "{query}".</p>
{/each}
</section>
<style>
.faq {
max-width: 40rem;
font-family: system-ui, sans-serif;This preview is shortened. You get the full content when you install it.
Changes in 1.0.0
First version.