Skip to content

SplitButtonWidget

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A split button with a primary action and a dropdown for secondary actions. The main button area triggers the primary action, while the dropdown arrow opens a menu.

csharp
public sealed record SplitButtonWidget : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<SplitButtonWidget>

Inheritance

ObjectHex1bWidgetSplitButtonWidget

Implements

Constructors

SplitButtonWidget()

Creates a split button. Use to set the primary action label and handler.

csharp
public SplitButtonWidget()

Properties

PrimaryLabel

The label for the primary action button.

Returns: String

csharp
public string PrimaryLabel { get; init; }

Methods

OnDropdownOpened(Action)

Sets a callback invoked when the dropdown menu is opened.

Parameters:

  • callback (Action): The callback invoked when the dropdown opens.

Returns: SplitButtonWidget

A new widget instance with the callback configured.

csharp
public SplitButtonWidget OnDropdownOpened(Action callback)

PrimaryAction(string, Action<SplitButtonClickedEventArgs>)

Sets the primary action with a label and synchronous handler.

Parameters:

Returns: SplitButtonWidget

A new widget instance with the primary action configured.

csharp
public SplitButtonWidget PrimaryAction(string label, Action<SplitButtonClickedEventArgs> handler)

PrimaryAction(string, Func<SplitButtonClickedEventArgs, Task>)

Sets the primary action with a label and asynchronous handler.

Parameters:

Returns: SplitButtonWidget

A new widget instance with the primary action configured.

csharp
public SplitButtonWidget PrimaryAction(string label, Func<SplitButtonClickedEventArgs, Task> handler)

SecondaryAction(string, Action<SplitButtonClickedEventArgs>)

Adds a secondary action to the dropdown menu.

Parameters:

Returns: SplitButtonWidget

A new widget instance with the action added.

csharp
public SplitButtonWidget SecondaryAction(string label, Action<SplitButtonClickedEventArgs> handler)

SecondaryAction(string, Func<SplitButtonClickedEventArgs, Task>)

Adds an asynchronous secondary action to the dropdown menu.

Parameters:

Returns: SplitButtonWidget

A new widget instance with the action added.

csharp
public SplitButtonWidget SecondaryAction(string label, Func<SplitButtonClickedEventArgs, Task> handler)

Fields

ActivateActionId

Action ID for activating the primary action.

Returns: ActionId

csharp
public static readonly ActionId ActivateActionId

OpenMenuActionId

Action ID for opening the dropdown menu.

Returns: ActionId

csharp
public static readonly ActionId OpenMenuActionId

Remarks

The split button renders as: [ Primary ▼ ] where "Primary" is the label from the primary action.

Interaction: Clicking the main label area (or pressing Enter when focused) triggers the primary action.Clicking the dropdown arrow (▼) opens a popup menu with secondary actions.Pressing Down arrow when focused also opens the dropdown menu.

Split buttons are useful when you have a default action that users commonly want, but also need to expose related alternative actions without cluttering the UI.

Examples

A save button with alternative save options:

csharp
ctx.SplitButton()
   .PrimaryAction("Save", e => SaveFile())
   .SecondaryAction("Save As...", e => SaveAs())
   .SecondaryAction("Save All", e => SaveAll())
   .SecondaryAction("Save Copy", e => SaveCopy())

Released under the MIT License.