Density and keyboard navigation

Fit/medium/compact density modes, two-pane keyboard navigation, and initial popup state.

Density modes

params.density picks between three sizing presets:

new HawkSearch({
  index: '/pagefind/',
  params: { density: 'fit' }, // 'fit' | 'medium' (default) | 'compact'
});
  • medium — the default sizing (unchanged from before density existed): a fixed-size dialog, 2 columns.
  • fit — a near-viewport dialog (96vw / 92vh), for a dedicated “search page” feel.
  • compact — a smaller dialog, forced to a single column with the preview pane hidden by default — see Reaching the preview pane in compact layouts.

Density composes with the existing breakpoint: whichever forces single-column wins, so a fit/medium dialog still degrades gracefully on narrow viewports even without compact.

The in-modal switcher

By default, the Result density button beside Escape reveals Fit, Medium, and Compact in a row to its left. Selecting a size calls search.setParams({ density }) internally. Hawk saves the visitor’s choice in localStorage (hawk:density) and restores it on the next construction unless config.params.density is set explicitly, which always wins over a stored preference. Set allowDensityToggle: false to fix density via config only and hide the switcher.

Minimal and configurable header actions

headerControls configures the two groups to the right of the search input. Pass false for a minimal header containing only the search bar:

new HawkSearch({
  index: '/pagefind/',
  headerControls: false,
});

Or configure the groups independently:

new HawkSearch({
  index: '/pagefind/',
  headerControls: {
    density: false, // hide Fit / Medium / Compact
    escape: true, // keep the Escape close button
  },
});

params.allowDensityToggle: false continues to disable density switching and therefore wins even when headerControls.density is true. Hiding the Escape button does not disable the Escape keyboard shortcut; use hotkeys.escape: false when the keyboard behavior must also be disabled.

Individual size buttons

Use a density object to omit individual buttons. Omitted keys remain enabled:

new HawkSearch({
  index: '/pagefind/',
  headerControls: { density: { fit: false, medium: true, compact: true } },
});

Setting all three keys to false omits the group. These options control the available buttons; they do not restrict params.density or the automatic narrow-screen layout.

The whole group can also be hidden or shown on an existing instance:

search.setParams({ allowDensityToggle: false });
search.setParams({ allowDensityToggle: true });

This retains the chosen density and the configured individual buttons. An explicit headerControls.density: false or headerControls: false keeps the group disabled.

Size control layouts

Use 'inline' to keep the size buttons visible in the header.

new HawkSearch({
  index: '/pagefind/',
  headerControls: { density: { layout: 'inline' } },
});

Use 'dropdown' for a vertical list below the button or 'slideout' to explicitly select the default.

In the slideout and dropdown, tab to Result density and press Enter or Space to expand it. Choosing a size or pressing Escape closes the choices and returns focus to the button. The animation respects the visitor’s reduced-motion preference.

Two-pane keyboard navigation

Tab moves from the search input through the visible header controls, filter tabs, results pane, preview pane, and any discovery links. Both panes are focus stops (tabindex="0").

  • Input focused (default): ↑/↓ move the selection, wrapping around; Enter navigates to the selected result.
  • Results pane focused: identical ↑/↓/Enter behavior. Typing any printable character refocuses the input and forwards the keystroke, so you can resume typing without an extra click.
  • Preview pane focused: ↑/↓/PgUp/PgDn/Home/End scroll its content instead of changing selection.

The results pane exposes the current selection via aria-activedescendant rather than making every result individually tabbable (the correct pattern for its role="listbox"), so pressing Tab moves from “the list” to “the preview” in one step regardless of how many results are showing.

Reaching the preview pane in compact layouts

In compact density (or below breakpoint), only one column is shown and the preview pane is hidden by default — there’s nowhere to put it next to the results. Tabbing into the preview pane reveals it in place of the results pane ([data-hawk-show-preview]); tabbing or clicking away hides it again. This is the only way to reach the preview in a single-column layout — there’s no separate “view result” button.

Scrollbars

The results pane, preview pane, and filter strip all get a themed scrollbar (thin, low-opacity at rest, brightening on hover or while actively scrolling — see Theming — token list for --hawk-scrollbar-thumb/-active). The scroll trigger fires on a scroll event regardless of cause, so keyboard-driven scrolling (arrow keys in the preview pane) lights it up the same as a mouse wheel, fading back to idle ~500ms after the last scroll. Both the hover and scroll triggers are Blink/WebKit-only (::-webkit-scrollbar-thumb) — the standards-track scrollbar-color property Firefox uses doesn’t support a separate hover/active state, so there the thumb stays at its idle color throughout.

Initial popup state

Three config keys shape what the modal shows the instant it opens, before the visitor has typed or clicked anything:

new HawkSearch({
  index: '/pagefind/',
  defaultTab: 'guides', // active tab on open — see the API reference's Tabs section
  defaultPreviewUrl: '/getting-started/',
  defaultPreviewTitle: 'Getting started',
  eagerResults: true, // default — set false to keep the results pane empty until the visitor types
  resultHydrationConcurrency: 6,
  maxCandidateResults: 54,
});
  • defaultPreviewUrl shows a specific page’s content in the preview pane as soon as the modal mounts — before Pagefind even loads, let alone before anything is selected. It uses the same fetch/extract path a real selection uses (Rich preview content), so it’s real rendered page content. A real result — from a click, a keyboard selection, or an eagerResults listing — replaces it automatically.
  • eagerResults (default true) runs an empty-query search as soon as Pagefind loads, so the results pane shows a default listing instead of “Type to search”. This is a behavior change from hawk’s very first releases, where the results pane stayed empty until the first keystroke — set eagerResults: false to keep that behavior.
  • resultHydrationConcurrency (default 6) bounds simultaneous Pagefind fragment requests. Hawk renders each ordered batch as soon as it completes instead of waiting for every candidate.
  • maxCandidateResults (default maxResults * 3) bounds how deeply Hawk hydrates Pagefind handles when exclusions or heading expansion make the final row count differ from the candidate count. It keeps Hawk’s own work predictable even when the backing index is very large.
  • defaultTab is documented in API reference — Tabs; it also determines which tab’s filter scopes the eagerResults listing.