ShowMore
Since 0.1.0-alpha.24Long content cut to its first lines, with a "Show more" button under them: a bio, a description, background notes in a side column. The button shows only when there is more than fits, and reads "Show less" once it's open. Where a whole section should hide behind its trigger, use Collapsible.
Long text in a card
Wrap long text in a ShowMore to show its first four lines. The Show more button appears only when there is more than fits, and reads Show less once the text is open.
Static
Preview
Background
Acme is expanding its marketing team ahead of a website launch planned for January. Olivia coordinates proposals and prefers email; Ethan signs off on anything that touches operations. Budget is agreed in principle for the redesign, and a photography project is likely to follow once the new product line is announced in the spring.
Code
@* An account's background in a narrow column: four lines, then the rest behind the button. *@
<Card Title="Background" TitleLevel="3" MaxWidth="22.Rem">
<ShowMore Lines="4">
<TextBlock Color="Color.Muted">
Acme is expanding its marketing team ahead of a website launch planned for January. Olivia coordinates
proposals and prefers email; Ethan signs off on anything that touches operations. Budget is agreed in
principle for the redesign, and a photography project is likely to follow once the new product line is
announced in the spring.
</TextBlock>
</ShowMore>
</Card>Add this example to a page with the izzy CLI:
izzy add component ShowMore --at <file>:<line>Lines and typed line breaks
Lines sets how many lines show. For text someone typed into a multi-line field, set KeepLines on the TextBlock so each line break starts a line; a blank line counts as one.
Static
Preview
Notes
Prefers email for proposals. A short call works for scope changes. Confirm the final decision-maker before closing.
Code
@* Notes a rep typed about a contact, line breaks and all: two lines, then the rest. *@
<Card Title="Notes" TitleLevel="3" MaxWidth="22.Rem">
<ShowMore Lines="2">
<TextBlock Color="Color.Muted" KeepLines>_notes</TextBlock>
</ShowMore>
</Card>
{
private readonly string _notes = "Prefers email for proposals.\nA short call works for scope changes.\n\nConfirm the final decision-maker before closing.";
}Mode support
| Feature | Static | Interactive |
|---|---|---|
| The whole text, readable | Yes | Yes |
| The cut to the first lines, and the Show more button | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, everything shows and there's no button.
Accessibility
- The content is all in the page, only cut from sight, so screen readers and find-in-page reach every word whether it's open or not.
- The button is a
buttonwitharia-expanded, named byMoreTextorLessText.
Parameters
| Prop | Type | Default |
|---|---|---|
ChildContentThe content. | RenderFragment? | |
LinesHow many lines show before the button (1 or more; defaults to 4). | int | 4 |
MoreTextThe button's text while the content is cut. | string? | computed |
LessTextThe button's text once everything shows. | string? | computed |
Plus 27 surface props, 17 item props and 4 common props.
Full APISee also
- Collapsible: hides a section behind a label that opens it.
- TextBlock: sets paragraphs, captions and labels in the library's text styles.