Layout
TwOnThisPage
TwOnThisPage is a Blazor table of contents component: an On this page list of section links that highlights the section being read as you scroll.
Last updated
Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at
https://github.com/twblazor/twblazor/issues.
Basic usage
Give
TwOnThisPage a list of OnThisPageItems, each pairing the Id of an element on the page with the text of its link.
The link to the section being read is highlighted as the page scrolls. The example lists this page's own sections, so scroll the page to see it follow along.
It is the same component as the "On this page" list beside every page of these docs.
Link paths
Every Blazor app has a
<base href>, which makes a bare #section link point at the site root instead of the current page.
Set BasePath to the current page's path so each link becomes /your-page#section.
RAZOR
<TwOnThisPage Items="@_sections" BasePath="/on-this-page" Class="max-w-xs" />Title and heading level
The heading defaults to "On this page", translated into the app's language. Set
Title to change it, and HeadingLevel so it fits the page's heading outline.
The navigation landmark is named after the heading, so screen reader users can find it in their list of landmarks.
RAZOR
<TwOnThisPage Items="@_sections" BasePath="/on-this-page" Title="Contents" HeadingLevel="3" Class="max-w-xs" />Fixed headers
A section counts as the one being read once its top passes a line 140 pixels below the top of the viewport.
Raise
Offset when a fixed header covers more of the page than that, or lower it for a page with nothing fixed at the top.
RAZOR
<TwOnThisPage Items="@_sections" BasePath="/on-this-page" Offset="240" Class="max-w-xs" />Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwOnThisPageTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
Title |
string | |
List |
string | |
Link |
string | |
LinkCurrent |
string |
Full reference: TwOnThisPageTheme on the API docs.