Searches the text projected into its default slot and highlights the matches. It uses the native CSS Custom Highlight API, so it does not change the DOM.

The component supports case-sensitive matching and programmatic navigation between matches. Navigation scrolls the active match into view. When the content changes, the component searches it again and keeps the active match where it can.

Slots
default — The content to search. Only content projected here takes part in the matching.

Whether the matching distinguishes upper and lower case. When true, only exact-case occurrences of searchText are highlighted.

caseSensitive: boolean

The string to search and highlight in the DOM content of the component. A change of this property starts a new search. An empty string clears all highlights.

searchText: string

The zero-based index of the active match. Returns 0 when there are no matches.

get current(): number

Returns number

The total number of matches found for the current searchText. Returns 0 when there are no matches or searchText is empty.

get size(): number

Returns number

Moves the active highlight to the next match. Wraps around to the first match after the last one.

next(options: HighlightNavigation): void

Parameters

  • options: HighlightNavigation

    Optional navigation options (e.g. preventScroll).

Returns void

Moves the active highlight to the previous match. Wraps around to the last match when going back from the first one.

previous(options: HighlightNavigation): void

Parameters

  • options: HighlightNavigation

    Optional navigation options (e.g. preventScroll).

Returns void

Re-runs the highlight search based on the current searchText and caseSensitive values, and makes the first match active.

The component also searches again by itself after its content changes.

search(): void

Returns void

Moves the active highlight to the match at the specified zero-based index.

setActive(index: number, options: HighlightNavigation): void

Parameters

  • index: number

    The zero-based index of the match to activate.

  • options: HighlightNavigation

    Optional navigation options (e.g. preventScroll).

Returns void