Skip to content

Headless UI

When the default card is not what you want, replace as much of it as you need. The library still owns the popover element, so measurement, collision-aware placement, focus management and dialog semantics keep working; you own everything inside it.

Three levels of customisation

Reach for the smallest one that does the job.

LevelHowUse it when
Restyle --bit-bonboarding-* custom properties - see theming The layout is right, the colours are not.
Recompose A step's Header, Body (its ChildContent in markup) and Footer One step needs a form, an image or a different set of buttons.
Replace BonboardingRoot.ChildContent, or a tour or step Template; OverlayTemplate and WaitingTemplate The card should look nothing like the default.

Recompose one step

In markup, a step's ChildContent is its body, with the default header and footer kept around it - the common case. Header and Footer replace those regions one at a time. All three are ordinary Razor, handed the step's render context. The first step below has a body of three buttons and no Next button: picking a plan moves the tour on. The second has a header and a footer of its own.

Live
Active projects
12
Usage this month
68%
Team members
7
Replacing the footer removes the close button along with everything else, so leave the user a way out - or keep CloseOnEscape on, as it is by default.
<BonboardingTour @ref="_tour" Id="recomposed">

    @* ChildContent is the step's body; the default header and footer stay. *@
    <BonboardingStep Id="plan" Anchor="new-project" Title="Choose a plan" ShowNext="false">
        @foreach (var plan in Plans)
        {
            <button @onclick="() => PickPlanAsync(context, plan)">@plan</button>
        }
    </BonboardingStep>

    @* Header and Footer replace those regions one at a time. *@
    <BonboardingStep Id="summary" Anchor="usage" Title="Your plan">
        <Header>
            <div class="bit-bonboarding-header"><h2 class="bit-bonboarding-title">A header of its own</h2></div>
        </Header>
        <ChildContent>The card around these regions is still the library's.</ChildContent>
        <Footer>
            <span>@context.ProgressText</span>
            <button @onclick="context.PreviousAsync">@context.PreviousLabel</button>
            <button data-bonboarding-autofocus @onclick="context.NextAsync">@context.NextLabel</button>
        </Footer>
    </BonboardingStep>

</BonboardingTour>

private async Task PickPlanAsync(BonboardingStepRenderContext context, string plan)
{
    _plan = plan;
    await context.NextAsync();
}

// In C#, the same regions are RenderFragment<BonboardingStepRenderContext> properties, and Template
// replaces the whole card for one step:
new BonboardingStepDefinition { Header = context => builder => { ... }, Body = ..., Footer = ..., Template = ... }

A card the library did not draw

This tour is drawn by a second BonboardingRoot on this page, handed the session it started and given its own ChildContent for the card, an OverlayTemplate for the dimming and a WaitingTemplate for a step whose target is not there yet - the last step waits two seconds for an element that never comes, then falls back to a centred card. Unstyled="true" drops the built-in card classes so the page's CSS starts from nothing.

Live Rendered by this page, not by the library
  • A host given an explicit Session claims it, and the layout's host stops drawing that session; the claim is released when the host is disposed, so navigating away hands the session back. Render such a host only once it has its session: a host without one is ambient, and draws whatever tour is active - beside the layout's host.
  • OverlayTemplate replaces the visuals only. The pointer blockers that implement Interaction are drawn separately and keep working, so a custom overlay does not have to reimplement click-through.
  • Mark the control that should take focus when a step appears with data-bonboarding-autofocus; otherwise the first focusable control does, then the dialog itself. The dialog keeps its label, its focus trap and its announcements whatever you put inside it - but its contents are yours: use real buttons and a sensible tab order.
@* This page: a second host that claims the session it started. Rendered only once there is one -
   a host without a Session is an ambient host, and would draw the page's other tours a second time. *@
@if (_session is not null)
{
    <BonboardingRoot Session="_session" Unstyled="true" PopoverClass="my-card">
        <ChildContent>
            <h2>@context.Title</h2>
            <p>@context.Description</p>
            <button @onclick="context.CloseAsync">Close</button>
            <button @onclick="context.PreviousAsync">@context.PreviousLabel</button>
            <button data-bonboarding-autofocus @onclick="context.NextAsync">@context.NextLabel</button>
        </ChildContent>

        <OverlayTemplate>
            @if (context.TargetRect is { } rect)
            {
                <svg class="my-overlay">
                    <mask id="hole">
                        <rect width="100%" height="100%" fill="white" />
                        <rect x="@Px(rect.X)" y="@Px(rect.Y)" width="@Px(rect.Width)" height="@Px(rect.Height)" rx="12" fill="black" />
                    </mask>
                    <rect width="100%" height="100%" fill="rgba(0,0,0,0.6)" mask="url(#hole)" />
                </svg>
            }
        </OverlayTemplate>

        <WaitingTemplate>Looking for the next part of the page…</WaitingTemplate>
    </BonboardingRoot>
}

private async Task StartAsync()
{
    _session = await BonboardingService.StartAsync(tour);
    StateHasChanged();
}

The render context

Every template - a step's header, body or footer, a step or tour Template, and the host's ChildContent, OverlayTemplate and WaitingTemplate - receives a BonboardingStepRenderContext as context. Templates are resolved most specific first: the step's Template, then the tour's, then the host's ChildContent, then the default card.

MemberWhat it is
Title, Description, ValidationMessage The step's text, already localised, and why CanAdvance last held the user, if it did.
Position, Count, ProgressText 1-based, counting only the steps that will be shown; ProgressText is "2 of 5", from the labels.
IsFirst, IsLast, IsWaiting Where the step stands, and whether its target is still being waited for.
NextLabel, PreviousLabel, SkipLabel, Labels NextLabel already reads the done label on the last step.
NextAsync, PreviousAsync, SkipAsync, CloseAsync, CompleteAsync, GoToAsync(id) Commands, as the default buttons use them.
InvokeAsync(action), IsRunning(action) Runs one of the step's Actions, and says whether its handler is still running (to show it busy).
TargetRect, Placement, Options The measured target, where the engine put the popover (side, alignment, arrow offset), and the step's resolved options.
Session, Step, Index The running session, the step's definition (its Data and Metadata included), and its index in the tour.

No host at all

Leave BonboardingRoot out and the library renders nothing: drive IBonboardingService and the session yourself, draw whatever you like from session.CurrentStep and session.TargetRect, and re-render on session.Changed. The trade-off is real: without the host nothing measures your popover, so session.Placement stays empty and positioning is yours - though the placement engine is public and pure. For almost every application, Unstyled="true" with your own ChildContent is the better trade.

var result = BonboardingPlacementEngine.Place(new BonboardingPlacementRequest
{
    Target = session.TargetRect!.Value.Inflate(8),
    Popover = new BonboardingSize(320, 180),
    Viewport = new BonboardingRect(0, 0, viewportWidth, viewportHeight),
    Preferred = BonboardingPlacement.Bottom,
    Offset = 12,
    ViewportPadding = 16,
    ArrowSize = 10,
    CornerRadius = 12,
    HasTarget = true,
});

// result.Popover is the rectangle to draw at; result.Side, result.Align and result.ArrowOffset place the arrow.

To see what the engine decides for a given target, popover and viewport without writing any code, ask the MCP server's placement inspector.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.

An unhandled error has occurred. Reload 🗙