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.
Properties
Section titled "Properties"caseSensitive
Section titled "caseSensitive"Whether the matching distinguishes upper and lower case.
When true, only exact-case occurrences of searchText are highlighted.
caseSensitive: boolean searchText
Section titled "searchText"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 Accessors
Section titled "Accessors"current
Section titled "current"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
Methods
Section titled "Methods"Moves the active highlight to the next match. Wraps around to the first match after the last one.
next(options: HighlightNavigation): void Parameters
- options:
HighlightNavigationOptional navigation options (e.g.
preventScroll).
Returns void
previous
Section titled "previous"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:
HighlightNavigationOptional navigation options (e.g.
preventScroll).
Returns void
search
Section titled "search"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
setActive
Section titled "setActive"Moves the active highlight to the match at the specified zero-based index.
setActive(index: number, options: HighlightNavigation): void Parameters
- index:
numberThe zero-based index of the match to activate.
- options:
HighlightNavigationOptional navigation options (e.g.
preventScroll).