Skip to main content

LgCrudToolbarButton

LgCrudToolbarButton specializes LgToolbarButton for toolbar menus that need to offer secondary actions such as rename, save, and delete to the right of the main entry.

<LgCrudToolbarButton Text="Profil"
OnRename="OnRenameAsync"
OnSave="OnSaveAsync"
OnRemove="OnRemoveAsync" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgToolbarButton → LgButton → LgAriaComponentBase → LgComponentBase
  • Interfaces: ILgComponentPolicies, IActionComponent, ILgFocusableComponent
  • NuGet package: Lagoon.UI
Specialized rendering

Secondary buttons (OnRename, OnSave, OnRemove) are rendered only when the component is placed in a LgToolbarMenu and the corresponding callback has a handler.

Usage​

Demo​

Try this component in the Lagoon showcase.

CRUD entry in a menu​

LgCrudToolbarButton is intended to be placed in a LgToolbarMenu. The main entry remains clickable, and secondary buttons are displayed to the right only for the provided callbacks.

ProfilesPage.razor
@inherits LgPage

<LgToolbar>
<LgToolbarGroup>
<LgToolbarMenu Text="#Profiles" IconName="@IconNames.All.PersonLinesFill">
<LgCrudToolbarButton Text="#DefaultProfile"
IconName="@IconNames.All.Person"
OnClick="OpenProfileAsync"
OnRename="RenameProfileAsync"
RenameButtonTooltip="#Rename"
RenameButtonAria="#RenameProfile"
OnSave="SaveProfileAsync"
OnSaveConfirmationMessage="#ConfirmSaveProfile"
SaveButtonTooltip="#Save"
SaveButtonAria="#SaveProfile"
OnRemove="RemoveProfileAsync"
OnRemoveConfirmationMessage="#ConfirmDeleteProfile"
RemoveButtonTooltip="#Delete"
RemoveButtonAria="#DeleteProfile" />
</LgToolbarMenu>
</LgToolbarGroup>
</LgToolbar>
ProfilesPage.razor.cs
public partial class ProfilesPage : LgPage
{
// Opens the main menu entry to view the selected profile.
private Task OpenProfileAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}

// Starts renaming; the secondary button is rendered only if this callback is defined.
private Task RenameProfileAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}

// Saves the profile after confirmation to avoid unintentional writing.
private Task SaveProfileAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}

// Removes the profile after confirmation; the action is separate from the main opening.
private Task RemoveProfileAsync(ActionEventArgs args)
{
return Task.CompletedTask;
}
}

Display only available actions​

Each secondary button is conditioned by its EventCallback. You can therefore expose only the actions allowed by the business context.

ProfilesPage.razor
@inherits LgPage

<LgToolbarMenu Text="#Profiles">
<LgCrudToolbarButton Text="#ReadOnlyProfile"
IconName="@IconNames.All.Eye"
OnClick="OpenProfileAsync" />

<LgCrudToolbarButton Text="#EditableProfile"
IconName="@IconNames.Edit"
OnClick="OpenProfileAsync"
OnRename="RenameProfileAsync"
RenameButtonTooltip="#Rename"
RenameButtonAria="#RenameProfile"
OnSave="SaveProfileAsync"
SaveButtonTooltip="#Save"
SaveButtonAria="#SaveProfile" />
</LgToolbarMenu>
Rendering outside a menu

If LgCrudToolbarButton is placed directly in a toolbar, it falls back to LgToolbarButton rendering and does not display secondary actions. Use it in LgToolbarMenu to benefit from the CRUD actions column.

Combine main action and command​

The main action inherits the capabilities of LgToolbarButton: OnClick, CommandName, CommandArgument, Uri, and Link. Secondary actions remain independent.

ProfilesPage.razor
@inherits LgPage

<LgToolbar OnCommand="OnToolbarCommandAsync">
<LgToolbarGroup>
<LgToolbarMenu Text="#Profiles">
<LgCrudToolbarButton Text="#CurrentProfile"
CommandName="open-profile"
CommandArgument="@_profileId"
OnRemove="RemoveProfileAsync"
OnRemoveConfirmationMessage="#ConfirmDeleteProfile"
RemoveButtonTooltip="#Delete"
RemoveButtonAria="#DeleteProfile" />
</LgToolbarMenu>
</LgToolbarGroup>
</LgToolbar>
ProfilesPage.razor.cs
public partial class ProfilesPage : LgPage
{
// Identifier of the selected profile, passed by the main entry via CommandArgument.
private int _profileId = 12;

// Centralizes profile opening without impacting CRUD secondary buttons.
private Task OnToolbarCommandAsync(CommandEventArgs args)
{
if (args.CommandName == "open-profile")
{
args.Handled = true;
App.NavigateTo(ProfilePage.Link((int)args.CommandArgument).Uri);
}
return Task.CompletedTask;
}
}

Properties​

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

NameTypeDefaultDeclared inDescription
OnRemoveEventCallback<ActionEventArgs>—LgCrudToolbarButtonCallback of the delete secondary button. The button is rendered only if this callback has a handler.
OnRemoveConfirmationMessagestringnullLgCrudToolbarButtonConfirmation message displayed before the OnRemove action.
OnRenameEventCallback<ActionEventArgs>—LgCrudToolbarButtonCallback of the rename secondary button. The button is rendered only if this callback has a handler.
OnSaveEventCallback<ActionEventArgs>—LgCrudToolbarButtonCallback of the save secondary button. The button is rendered only if this callback has a handler.
OnSaveConfirmationMessagestringnullLgCrudToolbarButtonConfirmation message displayed before the OnSave action.
RemoveButtonAriastringnullLgCrudToolbarButtonARIA label of the delete secondary button.
RemoveButtonTooltipstringnullLgCrudToolbarButtonTooltip of the delete secondary button.
RenameButtonAriastringnullLgCrudToolbarButtonARIA label of the rename secondary button.
RenameButtonTooltipstringnullLgCrudToolbarButtonTooltip of the rename secondary button.
SaveButtonAriastringnullLgCrudToolbarButtonARIA label of the save secondary button.
SaveButtonTooltipstringnullLgCrudToolbarButtonTooltip of the save secondary button.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgButtonAdditional HTML attributes applied to the rendered main element.
AutoFocusboolfalseLgButtonGives focus to the main button on first render.
ButtonSizeButtonSize?Toolbar.ButtonSize or ButtonSize.MediumLgButtonSize of the main button. LgToolbarButton.OnInitialized takes the size of the parent toolbar, otherwise Medium.
ChildContentRenderFragmentnullLgButtonCustom content of the main button.
CommandArgumentobjectnullLgButtonArgument associated with the main command sent to the handler.
CommandNamestringnullLgButtonName of the main command sent to the parent command handler (ICommandListener).
ConfirmationMessagestringnullLgButtonConfirmation message displayed before the main action. Incompatible with CommandName and IsSubmit.
CssClassstringnullLgButtonAdditional CSS classes added to the main entry.
DisabledboolfalseLgButtonDisables the main entry.
IconNamestringnullLgButtonIcon of the main entry.
IsSubmitboolfalseLgButtonIf true, the main button is of type submit and triggers the parent LgEditForm.
KindButtonKindToolbar.ButtonKind or ButtonKind.SecondaryLgButtonStyle of the main entry. The default behavior is that of LgToolbarButton.
LinkLgPageLinknullLgButtonLink information to a page. The Text and IconName of the link are taken if they are not defined.
OnClickEventCallback<ActionEventArgs>—LgButtonCallback triggered when clicking on the main entry.
PolicyEditstringnullLgButtonPolicy required to enable (edit) the main entry.
PolicyVisiblestringnullLgButtonPolicy required to display the main entry.
PreventDefaultboolfalseLgButtonCancels the default behavior of the click event. In a menu, rendering forces true for the main entry.
PreventDoubleClickbooltrueLgButtonDisables the button during execution of the main action to prevent double-click.
ShortcutKeystringnullLgButtonKeyboard shortcut character for the main action. Associated with Ctrl, or with Alt if prefixed by @.
StopPropagationbooltrueLgButtonStops the propagation of the click event of the main action. In a menu, rendering forces true.
TargetstringnullLgButtonName of the browser window in which to open the Uri.
TextstringnullLgButtonLabel of the main entry.
TooltipstringnullLgButtonTooltip of the main entry.
TooltipIsHtmlboolfalseLgButtonIndicates whether the content of the Tooltip is in HTML format (otherwise plain text).
TooltipPositionTooltipPositionTooltipPositionTooltipPosition.BottomLgButton
UristringnullLgButtonURI / route to open when clicking on the main entry.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute of the main entry.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute of the main entry.
Cascading parameters

LgCrudToolbarButton inherits cascading parameters from LgToolbarButton: Toolbar (LgToolbar), ToolbarMenuParent (LgToolbarMenu), as well as cascading parameters inherited from LgButton (ParentAuthorizeView, EditForm, ButtonSizeCascading, ParentCommandListener).

Events​

EventTypeDescription
OnClickEventCallback<ActionEventArgs>Main action inherited from LgButton.
OnRenameEventCallback<ActionEventArgs>Action of the rename secondary button.
OnSaveEventCallback<ActionEventArgs>Action of the save secondary button.
OnRemoveEventCallback<ActionEventArgs>Action of the delete secondary button.

ButtonKind​

Visual style of the main entry.

ValueDescription
PrimaryPrimary style.
SecondarySecondary style (default value outside custom toolbar).
SuccessSuccess style.
ErrorError style (danger).
WarningWarning style.
InfoInformation style.
LinkLink appearance.
GhostGhost style (transparent background).
CustomCustom style (no variant class imposed).

ButtonSize​

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

TooltipPosition​

ValueDescription
NoneUndefined position.
TopAbove.
RightTo the right.
BottomBelow (value set by LgToolbarButton).
LeftTo the left.

Accessibility​

  • Fill in SaveButtonAria, RemoveButtonAria, and RenameButtonAria when secondary buttons are displayed.
  • The main entry retains role="menuitem" when it is in a menu.
  • Secondary buttons use icons (PencilFill, Save2Fill, IconNames.Delete); their tooltips and ARIA labels must therefore be explicit.