Class TwMenu
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A button that opens a menu of actions and options, such as a column's options in a table or a row's actions.
public class TwMenu : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
- Inheritance
-
TwMenu
- Implements
- Inherited Members
Remarks
The menu follows the ARIA menu button pattern. The button says that it opens a menu and whether the menu is open. Enter, Space or Arrow Down open the menu on its first item and Arrow Up on its last. In the menu the arrow keys move between the items and wrap round, Home and End move to the first and last, and typing a letter moves to the next item starting with it. Escape closes the menu and returns focus to the button, and Tab closes it and moves on. Put TwMenuItem, TwMenuCheckboxItem, TwMenuDivider and TwMenuGroup in it.
Constructors
TwMenu()
public TwMenu()
Properties
ButtonClass
Gets or sets extra classes for the button.
[Parameter]
public string? ButtonClass { get; set; }
Property Value
ChildContent
Gets or sets the menu's items.
[Parameter]
public RenderFragment? ChildContent { get; set; }
Property Value
Dense
Whether the button uses its compact size.
[Parameter]
public bool Dense { get; set; }
Property Value
Disabled
Whether the button is disabled, so the menu cannot open.
[Parameter]
public bool Disabled { get; set; }
Property Value
Icon
[Parameter]
public Icon? Icon { get; set; }
Property Value
- Icon?
IconOnly
Whether the button shows only its Icon. Give it an AriaLabel, which is also shown as a tooltip; without one it is named with the localized Menu_Options text ("Options").
[Parameter]
public bool IconOnly { get; set; }
Property Value
IsOpen
Gets whether the menu is open.
public bool IsOpen { get; }
Property Value
Label
Gets or sets the text of the button that opens the menu. Also names the menu for assistive technology.
[Parameter]
public string? Label { get; set; }
Property Value
OpenChanged
Raised when the menu opens or closes.
[Parameter]
public EventCallback<bool> OpenChanged { 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 menu and returns focus to its button. The Escape key and a click outside the menu call this too.
[JSInvokable("Close")]
public Task CloseAsync()
Returns
- Task
A task that completes once the menu is closed.
CloseFromTab()
Closes the menu without moving focus, because Tab is already moving it on.
[JSInvokable]
public Task CloseFromTab()
Returns
- Task
A task that completes once the menu is closed.
DisposeAsync()
Removes the menu's listeners and releases the reference the script held to it.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes once the menu 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.
OpenAsync()
Opens the menu and moves focus to its first item.
public Task OpenAsync()
Returns
- Task
A task that completes once the menu is open.