diff --git a/docs/content/docs/ui.md b/docs/content/docs/ui.md index a578e9fe..c626a80d 100644 --- a/docs/content/docs/ui.md +++ b/docs/content/docs/ui.md @@ -169,3 +169,16 @@ new PagefindUI({ A set of custom ui strings to use instead of the automatically detected language strings. See the [translations/en.json](https://github.com/CloudCannon/pagefind/blob/main/pagefind_ui/translations/en.json) file for all available keys and their initial values. The items in square brackets such as `SEARCH_TERM` will be substituted dynamically when the text is used. + +### Autofocus + +{{< diffcode >}} +```javascript +new PagefindUI({ + element: "#search", ++ autofocus: true +}); +``` +{{< /diffcode >}} + +Enabling autofocus automatically directs attention to the search input field for enhanced user convenience, particularly beneficial when the UI is loaded within a modal dialog. However, exercise caution, as using autofocus indiscriminately may pose potential accessibility challenges. diff --git a/pagefind_ui/default/svelte/ui.svelte b/pagefind_ui/default/svelte/ui.svelte index 1522b7fa..1e7f18a7 100644 --- a/pagefind_ui/default/svelte/ui.svelte +++ b/pagefind_ui/default/svelte/ui.svelte @@ -34,6 +34,7 @@ export let merge_index = []; export let trigger_search_term = ""; export let translations = {}; + export let autofocus = false; let val = ""; $: if (trigger_search_term) { @@ -239,6 +240,7 @@ )} autocapitalize="none" enterkeyhint="search" + {autofocus} />