Pass the search term as highlight, and the text as children. A blank search shows the text as it is.
search-snippet.tsx
Highlight
<span>| Prop | Type | Default | Description |
|---|---|---|---|
| case | boolean | — | Match the exact case. Off by default: "key" also finds "Key". |
| ignore | boolean | — | Match letters with and without accents: "cafe" also finds "Café". It removes only the combining diacritical marks (U+0300 to U+036F: the accents of Latin, Greek, and Cyrillic), not the vowel signs of Devanagari or Thai, which change the word. Off by default. |
| whole | boolean | — | Match only whole words: "key" finds "key" but not "Keychain". Off by default. |
| locale | string | — | The language of the text, for lowercasing (Turkish "I" → "ı") and word edges. Without it, the matcher uses the locale-free toLowerCase, so the server and the browser give the same marks. A tag that is not valid BCP 47 ("en_US") falls back to no locale, with a warning in development, so a locale from user data cannot crash the render. |
| children | ReactNode | — | The content to search: a plain string, or rich content (nested elements). In rich content each text piece is searched on its own (see the rich-content notes on Highlight). |
| highlight | string | readonly string[] | NO_TERMS | One search term or many. Blank terms are skipped, so an empty search field marks nothing. |
| ranges | readonly HighlightRange[] | — | Ranges to mark, [start, end) in UTF-16 units, in place of highlight (a fuzzy search or a server gives them). They are clamped, sorted, merged, and widened to whole characters. Plain string children only: in rich content the indexes have no single text to point into. |
| tone | "destructive""info""neutral""success""warning" | — | The tone of every mark. |
| mark | Omit<MarkProps, "children" | "tone"> | — | Props for every mark: className, cue, data attributes. |
| render | — | The root element, in place of the <span>: render={<div />} for rich content with blocks (paragraphs, lists), which a <span> may not hold. It gets the props and the marked content. | |
| ...props | <span> attributes | — | Every other attribute goes to the <span>, with a ref. |
Built with
Installs with Highlight
- Components
- Mark





