Skip to content

PickerWidget

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A dropdown picker widget that shows a selected value and opens a list popup when activated. Selection state is owned by the node and preserved across reconciliation.

csharp
public sealed record PickerWidget : CompositeWidget<PickerNode>, IEquatable<Hex1bWidget>, IEquatable<CompositeWidget<PickerNode>>, IEquatable<PickerWidget>

Inheritance

ObjectHex1bWidget → CompositeWidget<PickerNode> → PickerWidget

Implements

Constructors

PickerWidget(IReadOnlyList<string>)

A dropdown picker widget that shows a selected value and opens a list popup when activated. Selection state is owned by the node and preserved across reconciliation.

Parameters:

csharp
public PickerWidget(IReadOnlyList<string> Items)

Properties

InitialSelectedIndex

The initial selected index when the picker is first created. Defaults to 0 (first item).

Returns: Int32

csharp
public int InitialSelectedIndex { get; init; }

Items

The list of items to choose from.

Returns: IReadOnlyList<String>

csharp
public IReadOnlyList<string> Items { get; init; }

Methods

BuildContentAsync(PickerNode, ReconcileContext)

Builds the picker's button content with popup behavior.

Parameters:

Returns: Task<Hex1bWidget>

csharp
protected override Task<Hex1bWidget> BuildContentAsync(PickerNode node, ReconcileContext context)

OnSelectionChanged(Action<PickerSelectionChangedEventArgs>)

Sets a synchronous handler called when the selection changes.

Parameters:

Returns: PickerWidget

csharp
public PickerWidget OnSelectionChanged(Action<PickerSelectionChangedEventArgs> handler)

OnSelectionChanged(Func<PickerSelectionChangedEventArgs, Task>)

Sets an asynchronous handler called when the selection changes.

Parameters:

Returns: PickerWidget

csharp
public PickerWidget OnSelectionChanged(Func<PickerSelectionChangedEventArgs, Task> handler)

UpdateNode(PickerNode)

Updates the node with widget properties before building content.

Parameters:

csharp
protected override void UpdateNode(PickerNode node)

Remarks

Picker is a composite widget that renders as a button showing the current selection. When clicked (or activated via keyboard), it opens an anchored popup containing a list of all available items. Selecting an item updates the picker and closes the popup.

The selection state () is owned by the node, not the widget. This means the picker maintains its selection across re-renders. Use the OnSelectionChanged method to react to selection changes.

Examples

csharp
ctx.Picker(["Apple", "Banana", "Cherry"])
    .OnSelectionChanged(e => Console.WriteLine($"Selected: {e.SelectedText}"));

Released under the MIT License.