Truncate
Clamps text to a number of lines, with an optional Show more button.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
expandable | boolean | false | Adds a "Show more" / "Show less" button when the text overflows its clamp. |
expanded | boolean | false | Shows the whole text. The button sets it; set it yourself to open or close the text programmatically. |
more-label | string | Show more | Label of the button while collapsed. |
less-label | string | Show less | Label of the button while expanded. |
Slots
| Name | Description |
|---|---|
(default) | Text to truncate. |
Events
| Name | Type | Description |
|---|---|---|
truncation-change | CustomEvent<boolean> | Fired when the text starts or stops overflowing its clamp; detail is the new truncated value. |
toggle | ToggleEvent | Fired after expanded changes from the button (newState is open or closed). |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
content | The clamped text container wrapping the default slot; the clamp applies to the text assigned to it. |
toggle | The "Show more" / "Show less" button, rendered when expandable is set and the text overflows. |
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-truncate__content--line-clamp | number | 3 | Number of visible lines while collapsed. |
--c2-truncate__content--color | color | inherit | |
--c2-truncate__content--font-size | pixel | inherit | |
--c2-truncate__content--line-height | line-height | inherit | |
--c2-truncate__toggle--margin-top | pixel | 4px | |
--c2-truncate__toggle--padding | padding | 0 | |
--c2-truncate__toggle--color | color | rgb(2, 101, 220) | |
--c2-truncate__toggle--background-color | color | transparent | |
--c2-truncate__toggle--font-size | pixel | 14px | |
--c2-truncate__toggle--font-weight | font-weight | 500 | |
--c2-truncate__toggle--border-radius | border-radius | 4px | |
--c2-truncate__toggle--text-decoration | text-decoration | none | |
--c2-truncate__toggle__hover--color | color | — | |
--c2-truncate__toggle__hover--text-decoration | text-decoration | underline | |
--c2-truncate__toggle__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-truncate__toggle__focus--outline-offset | pixel | 2px | |