CngxHighlight
projects/common/layout/text/highlight.directive.ts
Import#
import { CngxHighlight } from '@cngx/common/layout'
Description#
Search-text highlighting via <mark> elements.
Walks TEXT_NODE children of the host element, splits at match boundaries,
and wraps matched portions in <mark> elements. No innerHTML - safe by
construction. The <mark> element has correct native SR semantics (announced
as "highlighted" in most screen readers).
The original text nodes are kept by reference and re-inserted when the term changes or the directive is destroyed - Angular bindings targeting them (interpolations, structural directives) stay live.
Search result highlighting
<p [cngxHighlight]="searchTerm()">
Angular Signals represent a fundamental shift in reactivity.
</p>Case-sensitive matching
<p [cngxHighlight]="term()" [highlightCaseSensitive]="true">
CamelCase matters here.
</p>