Class TwPopover
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A button that opens a floating panel of rich, interactive content next to it, such as a short form, a set of filters or details about an item.
public class TwPopover : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
- Inheritance
-
TwPopover
- Implements
- Inherited Members
Remarks
The panel is a non-modal dialog positioned against the button. It opens on the side set by Placement, flips to the other side when there is no room, and stays inside the viewport as the page scrolls. Use TriggerContent for a trigger of your own.
Accessibility: the button says that it opens a dialog and whether it is open. Opening moves focus into the panel, and Escape closes it and returns focus to the button. Tabbing out of the panel or clicking outside it closes it and leaves focus where it went. The panel is named by its Title, or else by the button.
Constructors
TwPopover()
public TwPopover()
Properties
Align
Gets or sets how the panel lines up with the trigger. Defaults to Start.
[Parameter]
public PopoverAlign Align { get; set; }
Property Value
AutoFocus
Gets or sets whether opening the panel moves focus into it: onto an element marked
data-tw-autofocus, otherwise its first control, otherwise the panel itself. Defaults to
true. When off, the panel's content follows the button in the Tab order.
[Parameter]
public bool AutoFocus { get; set; }
Property Value
ButtonClass
Gets or sets extra classes for the button.
[Parameter]
public string? ButtonClass { get; set; }
Property Value
ChildContent
Gets or sets the panel's content.
[Parameter]
public RenderFragment? ChildContent { get; set; }
Property Value
CloseOnOutsideClick
Gets or sets whether clicking outside the panel closes it. Defaults to true.
[Parameter]
public bool CloseOnOutsideClick { get; set; }
Property Value
Dense
Gets or sets whether the button uses its compact size.
[Parameter]
public bool Dense { get; set; }
Property Value
Disabled
Gets or sets whether the button is disabled, so the panel cannot open.
[Parameter]
public bool Disabled { get; set; }
Property Value
Icon
[Parameter]
public Icon? Icon { get; set; }
Property Value
- Icon?
IconOnly
Gets or sets whether the button shows only its Icon. Give it an AriaLabel, which is also shown as a tooltip.
[Parameter]
public bool IconOnly { get; set; }
Property Value
IsOpen
Gets whether the panel is open.
public bool IsOpen { get; }
Property Value
Label
Gets or sets the text of the button that opens the panel.
[Parameter]
public string? Label { get; set; }
Property Value
Offset
Gets or sets the gap between the trigger and the panel, in pixels. Defaults to 8.
[Parameter]
public int Offset { get; set; }
Property Value
Open
Gets or sets whether the panel is open. Use with OpenChanged (@bind-Open) to open and
close it from code.
[Parameter]
public bool Open { get; set; }
Property Value
OpenChanged
Raised when the panel opens or closes.
[Parameter]
public EventCallback<bool> OpenChanged { get; set; }
Property Value
PanelClass
Gets or sets extra classes for the panel.
[Parameter]
public string? PanelClass { get; set; }
Property Value
Placement
Gets or sets which side of the trigger the panel opens on. Defaults to Bottom.
[Parameter]
public PopoverPlacement Placement { get; set; }
Property Value
ShowCloseButton
Gets or sets whether the panel has a close button in its top corner, which helps touch and screen reader users close it.
[Parameter]
public bool ShowCloseButton { get; set; }
Property Value
Title
Gets or sets a heading shown at the top of the panel, which also names it for assistive technology.
[Parameter]
public string? Title { get; set; }
Property Value
TriggerContent
Gets or sets a trigger of your own in place of the built-in button. Splat the context's Attributes onto it and call ToggleAsync from its click handler.
[Parameter]
public RenderFragment<PopoverTriggerContext>? TriggerContent { get; set; }
Property Value
Variant
Gets or sets the look of the button. Defaults to the button theme's own default.
[Parameter]
public ButtonVariant? Variant { 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 panel and returns focus to the button.
public Task CloseAsync()
Returns
- Task
A task that completes once the panel is closed.
CloseFromEscape()
Closes the panel when Escape is pressed, returning focus to the button.
[JSInvokable]
public Task CloseFromEscape()
Returns
- Task
A task that completes once the panel is closed.
CloseFromFocusOut()
Closes the panel when focus moves out of it, leaving focus where it went.
[JSInvokable]
public Task CloseFromFocusOut()
Returns
- Task
A task that completes once the panel is closed.
CloseFromOutsideClick()
Closes the panel after a click outside it, leaving focus where the click put it.
[JSInvokable("Close")]
public Task CloseFromOutsideClick()
Returns
- Task
A task that completes once the panel is closed.
DisposeAsync()
Removes the popover's listeners and releases the reference the script held to it.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes once the popover 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 panel.
public Task OpenAsync()
Returns
- Task
A task that completes once the panel is open.
ToggleAsync()
Opens the panel when it is closed, and closes it when it is open.
public Task ToggleAsync()
Returns
- Task
A task that completes once the panel has opened or closed.