Highlight
Marks the parts of a text that match a search query.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
query | string | string[] | — | Text to highlight. Assign an array to the property to highlight several queries at once. White space at either
end is kept, so " app" only matches after a space; an empty query highlights nothing. |
match-case | boolean | false | Compares letter case exactly. Off by default, so app matches Apple. |
ignore-accents | boolean | false | Ignores accents and other diacritics, so cafe matches café and the other way round. |
whole-word | boolean | false | Only highlights matches that are whole words, so app no longer matches inside Apple. |
words | boolean | false | Splits the query on white space and highlights every word on its own, the way a search box usually matches. |
active-index | number | -1 | Zero-based index of the match drawn as the current one (part active), for a find bar stepping through the
matches; -1 marks none. When it changes, the match is scrolled into view. |
Slots
| Name | Description |
|---|---|
(default) | The text to search. Only its text content is used: elements inside it are read as plain text. |
Events
| Name | Type | Description |
|---|---|---|
match-change | CustomEvent<number> | Fired when the number of matches changes; detail is the new matchCount. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
text | Wrapper drawing the text read from the default slot, matches marked inside it. Before the element connects (a server render) it wraps the default slot itself. |
mark | Every highlighted match, a <mark> inside the text wrapper. |
active | The match at active-index, which also carries the mark part. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-highlight__mark--color | color | inherit | |
--c2-highlight__mark--background-color | color | rgba(250, 204, 21, 0.4) | |
--c2-highlight__mark--font-weight | font-weight | inherit | |
--c2-highlight__mark--padding | padding | 0 | |
--c2-highlight__mark--border-radius | border-radius | 2px | |
--c2-highlight__mark--text-decoration | text-decoration | none | |
--c2-highlight__mark--box-shadow | box-shadow | none | |
--c2-highlight__mark__active--color | color | inherit | |
--c2-highlight__mark__active--background-color | color | rgba(251, 146, 60, 0.6) | |
--c2-highlight__mark__active--font-weight | font-weight | inherit | |
--c2-highlight__mark__active--box-shadow | box-shadow | 0 0 0 1px rgba(234, 88, 12, 0.8) | |