Highlight
A text component that visually highlights matching substrings via a query prop. Useful for search-result lists where the matching positions are runtime-determined.
Highlight vs. Mark:
<x-wirekit::wraps every occurrence ofhighlight> queryinside the slot dynamically.<x-wirekit::is a static wrapper — author decides where themark> <mark>goes. Use Highlight for query/search-match rendering, Mark for editorial emphasis where the highlighted region is known at author-time.
Basic Usage
Multiple Matches
All occurrences of the query are highlighted.
Case-Insensitive
Matching is case-insensitive, but the original casing is preserved in the output. That holds beyond ASCII as well: query="über" finds "Über". The query is compared with the text a reader sees, so query="Tom & Jerry" finds it in content written as Tom & Jerry, and a search for amp never matches inside that entity.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
query |
string|null | null |
Substring to search for and highlight |
as |
string | 'span' |
HTML element to render |
scope |
string|null | null |
Scoped personalization name |
Accessibility
- Each match is a native
<mark>element. Whether a screen reader announces a mark depends on the reader and its settings, so the highlight adds emphasis for a sighted reader and is never the only sign that a result matches: the result being in the list already says so. - The text itself is unchanged, so find in page and copy and paste meet it whole.
Keyboard Interaction
This component is purely presentational and does not respond to keyboard input.
Design Tokens
Highlighted matches use the same tokens as Mark:
| Token | Used for |
|---|---|
--color-wk-warning-bg |
Highlight background |
--color-wk-text |
Text color |
--radius-wk-sm |
Border radius |