Skip to content

Block 102 of 297

Search Results

Search box, result count and results with type badges and highlighted matches, plus a helpful no-results state.

Puck key
SearchResultsBlock
Export
searchResultsBlock
React component
<SearchResults />
Path
components/puck/search-results-block.tsx
Dependencies
None
License
MIT

About this block

When to use it, how to write for it, and what to change in the code.

What it's for

A results page layout: a search box prefilled with the visitor's terms, a result count, and a numbered list of results with type badges, dates, URLs and excerpts where the search words are highlighted. When the list is empty, a dashed panel offers suggested links instead. The box and button stack on phones.

  • The site search page for a city, library or parks department
  • A searchable resource center or knowledge base
  • Designing and testing the no-results state before search is wired up
Writing the content
  • Results are entered or bound as data, up to 50 per page. Pair the block with Pagination for longer result sets.
  • Fill Total results when results span several pages; otherwise the count shows only the items listed.
  • Search terms of three letters or more are highlighted in each Excerpt, so keep excerpts to a sentence or two of real page text.
  • Use the Show setting to preview the No results state, and offer up to 8 Suggested links to popular pages.
Accessibility
  • The form has role="search" and a real, visually hidden label from Search box label, so it doesn't rely on placeholder text.
  • Highlights use the mark element, and result titles are headings one level below the main Heading level, which defaults to H1 for a dedicated search page.
  • Each result is one link stretched over its row with a focus outline (WCAG 2.4.7).
Customizing the code
  • Highlight color is bg-indigo-100 in the highlight() function, and type badges use indigo-50 and indigo-800.
  • The column width is max-w-3xl; widen it for longer titles or URLs.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Headingtext
  • Heading levelselect
  • Search termstext
  • Search page URLtext
  • Search parameter nametext
  • Search box labeltext
  • Button texttext
  • Total resultstext
  • Resultsarray
  • Showradio
  • No-results headingtext
  • No-results texttextarea
  • Suggested linksarray