Skip to main content

LgToolbarButton

LgToolbarButton is the variant of LgButton adapted to Lagoon toolbars. Placed directly in a toolbar, it renders as a button; placed in an LgToolbarMenu, it renders as a menu item.

<LgToolbarButton Text="Item 1" IconName="@IconNames.All.GearFill" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgButton → LgAriaComponentBase → LgComponentBase
  • Interfaces: ILgComponentPolicies, IActionComponent, ILgFocusableComponent
  • NuGet package: Lagoon.UI
Behavior in a menu

When the button is placed in LgToolbarMenu, the rendered output becomes a menu link (role="menuitem") and the click attributes are forced with preventDefault and stopPropagation.

Usage​

Demo​

Try this component in the Lagoon showcase.

Button in a toolbar​

Placed in an LgToolbarGroup, LgToolbarButton behaves as an LgButton adapted to the toolbar. It picks up the default size and style from the parent LgToolbar, unless ButtonSize or Kind are set on the button.

OrdersPage.razor
@inherits LgPage

<LgToolbar ButtonKind="ButtonKind.Secondary" ButtonSize="ButtonSize.Small">
<LgToolbarGroup>
<LgToolbarButton Text="#Refresh" IconName="@IconNames.All.ArrowRepeat" OnClick="RefreshAsync" />
<LgToolbarButton Text="#Save" IconName="@IconNames.Save" Kind="ButtonKind.Primary" OnClick="SaveAsync" />
<LgToolbarButton Text="#Delete"
IconName="@IconNames.Delete"
Kind="ButtonKind.Error"
ConfirmationMessage="#ConfirmDelete"
OnClick="DeleteAsync" />
</LgToolbarGroup>
</LgToolbar>
OrdersPage.razor.cs
public partial class OrdersPage : LgPage
{
// Reloads the data from the toolbar without leaving the current page.
private Task RefreshAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}

// Saves the current item; the primary button forces the primary style here.
private Task SaveAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}

// Deletes the item after user confirmation to avoid accidental deletions.
private Task DeleteAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}
}

Button rendered in a menu​

In an LgToolbarMenu, the same component renders as a menu entry (role="menuitem"). The rendering forces preventDefault and stopPropagation to keep the dropdown list's behavior.

OrdersPage.razor
@inherits LgPage

<LgToolbar>
<LgToolbarGroup>
<LgToolbarMenu Text="#MoreActions" IconName="@IconNames.All.GearFill">
<LgToolbarButton Text="#Duplicate" IconName="@IconNames.All.Files" OnClick="DuplicateAsync" />
<LgToolbarButton Text="#Archive" IconName="@IconNames.All.Archive" CommandName="archive" />
<LgToolbarMenuItemSeparator />
<LgToolbarButton Text="#Delete" IconName="@IconNames.Delete" Kind="ButtonKind.Error" OnClick="DeleteAsync" />
</LgToolbarMenu>
</LgToolbarGroup>
</LgToolbar>

Link takes over the URI, title, and icon of an LgPageLink. This is the recommended way to navigate to a Lagoon page without duplicating the route.

OrdersPage.razor
@inherits LgPage

<LgToolbar>
<LgToolbarGroup>
<LgToolbarButton Link="@CustomersPage.Link()" />
<LgToolbarButton Link="@ReportsPage.Link()" Target="_blank" Text="#OpenReportInNewTab" />
</LgToolbarGroup>
</LgToolbar>
Value priority

If Text or IconName are provided on the button, they replace the values coming from Link. The URI comes from Uri if set, otherwise from Link.Uri.

Command relayed to the toolbar​

Use CommandName to avoid declaring a handler on every button. CommandArgument can carry the business identifier or the current filter.

OrdersPage.razor
@inherits LgPage

<LgToolbar OnCommand="OnToolbarCommandAsync">
<LgToolbarGroup>
<LgToolbarButton Text="#Open" CommandName="open" CommandArgument="@_selectedOrderId" />
<LgToolbarButton Text="#Export" CommandName="export" ShortcutKey="e" Tooltip="#ExportShortcut" />
</LgToolbarGroup>
</LgToolbar>
OrdersPage.razor.cs
public partial class OrdersPage : LgPage
{
// Identifier of the current row, passed via CommandArgument to the centralized actions.
private int _selectedOrderId = 42;

// Processes the commands emitted by the buttons and marks the consumed commands.
private Task OnToolbarCommandAsync(CommandEventArgs args)
{
if (args.CommandName == "open")
{
args.Handled = true;
App.NavigateTo(OrderDetailPage.Link((int)args.CommandArgument).Uri);
}
return Task.CompletedTask;
}
}
Combinations to avoid

As with LgButton, ConfirmationMessage must not be combined with CommandName nor with IsSubmit. For a confirmed action, use OnClick instead.

Properties​

All [Parameter] properties of the component, including inherited ones.

NameTypeDefaultDeclared inDescription
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgButtonAdditional HTML attributes applied to the rendered element (captures unmatched values).
AutoFocusboolfalseLgButtonGives focus to the button on first render.
ButtonSizeButtonSize?Toolbar.ButtonSize or ButtonSize.MediumLgButtonButton size. LgToolbarButton.OnInitialized picks up the size of the parent toolbar, otherwise Medium.
ChildContentRenderFragmentnullLgButtonCustom content of the button.
CommandArgumentobjectnullLgButtonArgument associated with the command sent to the handler. Use primitive types or string to optimize rendering.
CommandNamestringnullLgButtonName of the command sent to the parent command handler (ICommandListener).
ConfirmationMessagestringnullLgButtonConfirmation message displayed before the action. Incompatible with CommandName and IsSubmit.
CssClassstringnullLgButtonAdditional CSS classes. In a menu, they are added to the dropdown-item d-flex element.
DisabledboolfalseLgButtonDisables the button.
IconNamestringnullLgButtonDisplayed icon. Used via IconName="@IconNames.All.MyIcon".
IsSubmitboolfalseLgButtonIf true, the button is of type submit and triggers the parent LgEditForm.
KindButtonKindToolbar.ButtonKind or ButtonKind.SecondaryLgButtonButton style. The constructor initializes a sentinel value, then OnInitialized picks up the toolbar's value or Secondary.
LinkLgPageLinknullLgButtonLink information pointing to a page. The link's Text and IconName are reused if not set.
OnClickEventCallback<ActionEventArgs>—LgButtonCallback triggered when the button is clicked.
PolicyEditstringnullLgButtonPolicy required to enable (edit) the button.
PolicyVisiblestringnullLgButtonPolicy required to display the button.
PreventDefaultboolfalseLgButtonCancels the default behavior of the click event (@onclick:preventDefault). In a menu, the rendering forces true.
PreventDoubleClickbooltrueLgButtonDisables the button while the action runs, to prevent double-clicks.
ShortcutKeystringnullLgButtonKeyboard shortcut character. Combined with Ctrl, or with Alt if prefixed with @.
StopPropagationbooltrueLgButtonStops propagation of the click event (@onclick:stopPropagation). In a menu, the rendering forces true.
TargetstringnullLgButtonName of the browser window in which to open the Uri.
TextstringnullLgButtonLabel of the button or menu entry.
TooltipstringnullLgButtonTooltip.
TooltipIsHtmlboolfalseLgButtonIndicates whether the Tooltip content is in HTML format (otherwise plain text).
TooltipPositionTooltipPositionTooltipPosition.BottomLgButtonTooltip position. The LgToolbarButton constructor sets Bottom.
UristringnullLgButtonURI / route to open on click. In a menu, the href attribute is # if the URI is empty.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute (translated by GetTranslatedAriaLabel).
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

LgToolbarButton consumes Toolbar (LgToolbar) to retrieve default values, ToolbarMenuParent (LgToolbarMenu) to adapt its rendering in a menu, and the cascading parameters inherited from LgButton: ParentAuthorizeView, EditForm, ButtonSizeCascading, and ParentCommandListener.

Events​

EventTypeDescription
OnClickEventCallback<ActionEventArgs>Triggered on click (or keyboard shortcut). ActionEventArgs notably exposes a CancellationToken when the action runs inside a WaitingContext.

ButtonKind​

Visual style of the button.

ValueDescription
PrimaryPrimary style.
SecondarySecondary style (default value outside a custom toolbar).
Success"Success" style.
Error"Error" style (danger).
Warning"Warning" style.
Info"Info" style.
LinkLink appearance.
Ghost"Ghost" style (transparent background).
CustomCustom style (no variant class imposed).

ButtonSize​

ValueDescription
MediumStandard size (default value outside a custom toolbar).
SmallReduced size.
LargeLarge size.

TooltipPosition​

ValueDescription
NoneUndefined position.
TopAbove.
RightOn the right.
BottomBelow (value set by LgToolbarButton).
LeftOn the left.

Accessibility​

  • In a menu, the component renders role="menuitem" and keeps tabindex="0".
  • Set AriaLabel or AriaLabelledBy when the button only displays an icon.
  • Text remains the simplest label to make the action understandable to users and assistive technologies.