Class TwDrawer
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A panel that slides in from an edge of the screen over the page, for a form, a set of filters, the details of an item or navigation on a small screen. From the bottom edge it is a bottom sheet.
public class TwDrawer : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
- Inheritance
-
TwDrawer
- Implements
- Inherited Members
Remarks
Open and close it with @bind-Open, or from code with OpenAsync() and CloseAsync().
The content is first rendered when the drawer first opens and is kept after that, so what was typed into it
survives closing it again.
Accessibility: the panel is a dialog named by its Title and described by its
Description. Opening moves focus into it: onto an element marked data-tw-autofocus,
otherwise its first control, otherwise the panel itself. A Modal drawer keeps Tab inside it, makes
the page behind it inert and stops the page from scrolling. Escape, the close button and a click on the backdrop
close it, and focus goes back to the element that had it before the drawer opened.
Constructors
TwDrawer()
public TwDrawer()
Properties
BackdropClass
Gets or sets extra classes for the backdrop.
[Parameter]
public string? BackdropClass { get; set; }
Property Value
ChildContent
Gets or sets the drawer's body content.
[Parameter]
public RenderFragment? ChildContent { get; set; }
Property Value
CloseOnBackdropClick
Gets or sets whether a click on the backdrop closes a modal drawer. Defaults to true.
[Parameter]
public bool CloseOnBackdropClick { get; set; }
Property Value
CloseOnEscape
Gets or sets whether Escape closes the drawer. Defaults to true.
[Parameter]
public bool CloseOnEscape { get; set; }
Property Value
ContentClass
Gets or sets extra classes for the body.
[Parameter]
public string? ContentClass { get; set; }
Property Value
Description
Gets or sets a line of text under the Title, which screen readers announce with the name.
[Parameter]
public string? Description { get; set; }
Property Value
FooterContent
Gets or sets content shown in a footer below the body, such as the drawer's actions. The footer stays in view while the body scrolls.
[Parameter]
public RenderFragment? FooterContent { get; set; }
Property Value
IsOpen
Gets whether the drawer is open.
public bool IsOpen { get; }
Property Value
Modal
Gets or sets whether the drawer blocks the page behind it with a backdrop. Defaults to true. When off, the page stays usable while the drawer is open, as a side sheet.
[Parameter]
public bool Modal { get; set; }
Property Value
Open
Gets or sets whether the drawer is open. Use with OpenChanged (@bind-Open).
[Parameter]
public bool Open { get; set; }
Property Value
OpenChanged
Raised when the drawer opens or closes.
[Parameter]
public EventCallback<bool> OpenChanged { get; set; }
Property Value
Position
Gets or sets the edge of the screen the drawer slides in from. Defaults to End.
[Parameter]
public DrawerPosition Position { get; set; }
Property Value
ShowCloseButton
Gets or sets whether the header has a close button. Defaults to true. Keep it unless the drawer has another visible way to close it, as touch and screen reader users rely on it.
[Parameter]
public bool ShowCloseButton { get; set; }
Property Value
Size
Gets or sets how far the drawer reaches into the screen: its width on the start or end edge, its height on the top or bottom edge. Defaults to Medium.
[Parameter]
public DrawerSize Size { get; set; }
Property Value
Title
Gets or sets the heading at the top of the drawer, which also names it for assistive technology.
[Parameter]
public string? Title { get; set; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
CloseAsync()
Closes the drawer and returns focus to the element that had it before the drawer opened.
public Task CloseAsync()
Returns
- Task
A task that completes once the drawer is closed.
CloseFromEscapeAsync()
Closes the drawer when Escape is pressed. Invoked from JavaScript, which listens on the document and only calls the most recently opened dialog, drawer or popover.
[JSInvokable("CloseFromEscape")]
public Task CloseFromEscapeAsync()
Returns
- Task
A task that completes once the drawer is closed.
DisposeAsync()
Releases the drawer's focus trap, background inert-ing, scroll lock and Escape listener, and the reference the script held to it.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes once the drawer is cleaned up.
OnAfterRenderAsync(bool)
Method invoked after each time the component has been rendered interactively and the UI has finished updating (for example, after elements have been added to the browser DOM). Any ElementReference fields will be populated by the time this runs.
This method is not invoked during prerendering or server-side rendering, because those processes are not attached to any live browser DOM and are already complete before the DOM is updated.
Note that the component does not automatically re-render after the completion of any returned Task, because that would cause an infinite render loop.
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRenderboolSet to
trueif this is the first time OnAfterRender(bool) has been invoked on this component instance; otherwisefalse.
Returns
Remarks
The OnAfterRender(bool) and OnAfterRenderAsync(bool) lifecycle methods
are useful for performing interop, or interacting with values received from @ref.
Use the firstRender parameter to ensure that initialization work is only performed
once.
OnParametersSetAsync()
Method invoked when the component has received parameters from its parent in the render tree, and the incoming values have been assigned to properties.
protected override Task OnParametersSetAsync()
Returns
OpenAsync()
Opens the drawer.
public Task OpenAsync()
Returns
- Task
A task that completes once the drawer is open.
ToggleAsync()
Opens the drawer when it is closed, and closes it when it is open.
public Task ToggleAsync()
Returns
- Task
A task that completes once the drawer has opened or closed.