Layout
TwDrawer
TwDrawer is a Blazor drawer component: a panel that slides in from any edge of the screen, as a side sheet or a bottom sheet, with focus management built in.
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
Bind
Open with @bind-Open and open it from a button. Give it a Title, which also names it for screen readers, and an optional Description. Put the actions in FooterContent: the footer stays in view while the body scrolls. The drawer slides in from the end edge, moves focus to its first field, and closes on Escape, on the close button, or on a click on the backdrop.Position
Set
Position to slide the drawer in from another edge. Start and End follow the reading direction, so they swap sides in a right to left layout. Bottom makes a bottom sheet, which suits a phone, where it sits near the thumb.Size
Set
Size to Small, Medium (the default), Large or Full. On the start and end edges it sets the width, on the top and bottom edges the most height the drawer takes before its body scrolls. Below Full, a side drawer leaves a strip of the page showing on a phone, so the backdrop can still be tapped to close it.Action sheet
A bottom sheet with a list of actions is a familiar pattern on a phone. Make each action a button tall enough to tap, with its icon beside a text label. The drawer has no title here, so it is named with
AriaLabel, and ShowCloseButton="false" drops the close button because the sheet has a Cancel action of its own.Non-modal side sheet
Set
Modal="false" for a side sheet that sits over the page without blocking it: there is no backdrop, Tab can leave the drawer, and the page behind it still scrolls and responds. Use it for details or help that people read alongside their work. Escape and the close button still close it.Opening from code
Call
OpenAsync, CloseAsync and ToggleAsync on a reference to the drawer, or set the bound value. Set CloseOnBackdropClick="false" where a stray click could lose work: Escape, the close button and the footer still close it. Put data-tw-autofocus on the element that should take focus when the drawer opens.Accessibility
The panel is a dialog named by its
Title (or AriaLabel) and described by its Description. Opening it moves focus inside: onto an element marked data-tw-autofocus, else the first control in its body or footer, else the panel itself so its name is read out. A modal drawer keeps Tab inside it, makes the page behind it inert and stops the page scrolling; toasts stay reachable. Escape closes it wherever focus is, and closing it returns focus to the control that opened it. While closed, the panel is hidden from assistive technology and out of the Tab order. The slide is turned off when the operating system asks for reduced motion. A dialog opened from inside a drawer, such as a confirmation, works as usual and Escape closes it first.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwDrawerTheme), 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 |
|---|---|---|
Root |
string | |
Backdrop |
string | |
Panel |
string | |
Start |
string | |
End |
string | |
Top |
string | |
Bottom |
string | |
SmallWidth |
string | |
MediumWidth |
string | |
LargeWidth |
string | |
FullWidth |
string | |
SmallHeight |
string | |
MediumHeight |
string | |
LargeHeight |
string | |
FullHeight |
string | |
Header |
string | |
Heading |
string | |
Title |
string | |
Description |
string | |
CloseButton |
string | |
Content |
string | |
Footer |
string |
Full reference: TwDrawerTheme on the API docs.