CngxTruncate
projects/common/layout/text/truncate.directive.ts
Import#
import { CngxTruncate } from '@cngx/common/layout'
Description#
Manages text truncation with expand/collapse state detection.
Applies -webkit-line-clamp when collapsed and detects whether the text
is actually clamped (content overflows). Exposes isClamped so the consumer
can conditionally show a "Show more" toggle only when needed.
The expanded state supports two-way binding (controlled + uncontrolled).
Basic truncation with toggle
<p [cngxTruncate]="3" [(expanded)]="expanded" #trunc="cngxTruncate">
Long text content that may or may not overflow…
</p>
@if (trunc.isClamped() || trunc.expanded()) {
<button (click)="expanded.set(!expanded())"
[attr.aria-expanded]="expanded()">
{{ expanded() ? 'Show less' : 'Show more' }}
</button> * }Metadata#
Host#
Relationships
Index#
Properties
Outputs
Inputs#
Whether the text is expanded (full content visible). Supports two-way binding.
falseOutputs#
Instance Properties#
unknownWhether the text content actually exceeds the line limit and is being clamped.
this.isClampedState.asReadonly()HostBindings#
| Binding | Expression |
|---|---|
[style.-webkit-line-clamp] | clampValue() |
[style.display] | displayValue() |
[style.-webkit-box-orient] | orientValue() |
[style.overflow] | overflowValue() |