Class Sealed
public sealed class MokaJsonContextMenu : ComponentBase, System.IAsyncDisposable

Namespace: Moka.Blazor.Json.Components

Context menu component with customizable actions per node. Positioned entirely via C# inline styles to avoid Blazor/JS DOM conflicts.

Inheritance

Inherits from: ComponentBase

Implements: System.IAsyncDisposable

Properties

NameDescription
Actions The list of available context actions.
IsVisible Whether the context menu is currently visible.
NodeContext The context of the node on which the menu was invoked.
OnDismiss Callback when the context menu should be dismissed.

Actions

[Parameter]
public IReadOnlyList<MokaJsonContextAction>? Actions { get; set; }

The list of available context actions.

IsVisible

[Parameter]
public bool IsVisible { get; set; }

Whether the context menu is currently visible.

NodeContext

[Parameter]
public MokaJsonNodeContext? NodeContext { get; set; }

The context of the node on which the menu was invoked.

OnDismiss

[Parameter]
public EventCallback OnDismiss { get; set; }

Callback when the context menu should be dismissed.

Methods

NameDescription
DismissContextMenu() Called from JS when a click outside the menu occurs.
DisposeAsync()
ShowAsync(double clientX, double clientY) Shows the context menu at the given viewport coordinates.

DismissContextMenu()

[JSInvokable]
public Task DismissContextMenu()

Called from JS when a click outside the menu occurs.

ShowAsync(double clientX, double clientY)

public Task ShowAsync(double clientX, double clientY)

Shows the context menu at the given viewport coordinates.

Type Relationships
classDiagram
    style MokaJsonContextMenu fill:#f9f,stroke:#333,stroke-width:2px
    MokaJsonContextMenu --|> ComponentBase : inherits
    MokaJsonContextMenu ..|> IAsyncDisposable : implements
View Source
/// <summary>
///     Context menu component with customizable actions per node.
///     Positioned entirely via C# inline styles to avoid Blazor/JS DOM conflicts.
/// </summary>
public sealed partial class MokaJsonContextMenu : ComponentBase, IAsyncDisposable
{
#region Injected Services
#endregion
#region IAsyncDisposable
    /// <inheritdoc/>
    public async ValueTask DisposeAsync()
    {
        await RemoveDismissListenerAsync();
        _selfRef?.Dispose();
    }

#endregion
#region Parameters
    /// <summary>The list of available context actions.</summary>
    [Parameter]
    public IReadOnlyList<MokaJsonContextAction>? Actions { get; set; }

    /// <summary>Whether the context menu is currently visible.</summary>
    [Parameter]
    public bool IsVisible { get; set; }

    /// <summary>The context of the node on which the menu was invoked.</summary>
    [Parameter]
    public MokaJsonNodeContext? NodeContext { get; set; }

    /// <summary>Callback when the context menu should be dismissed.</summary>
    [Parameter]
    public EventCallback OnDismiss { get; set; }

#endregion
#region State Fields
#endregion
#region Computed Properties
#endregion
#region Public API
    /// <summary>
    ///     Shows the context menu at the given viewport coordinates.
    /// </summary>
    public async Task ShowAsync(double clientX, double clientY)
    {
        // Clean up previous dismiss listener if any
        await RemoveDismissListenerAsync();
        _left = clientX;
        _top = clientY;
        StateHasChanged();
        // Register a dismiss listener for clicks outside
        _selfRef ??= DotNetObjectReference.Create(this);
        _dismissListenerId = await Interop.AddContextMenuDismissListenerAsync(_selfRef, MenuId);
    }

    /// <summary>
    ///     Called from JS when a click outside the menu occurs.
    /// </summary>
    [JSInvokable]
    public async Task DismissContextMenu()
    {
        await RemoveDismissListenerAsync();
        await OnDismiss.InvokeAsync();
    }
#endregion
#region Private Methods
#endregion
}
Was this page helpful?