Skip to content

Commit

Permalink
Fix #1425 - implement EventCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
vnbaaij committed Feb 6, 2024
1 parent 0ca8175 commit 3281163
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Core/Components/Anchor/FluentAnchor.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public partial class FluentAnchor : FluentComponentBase, IAsyncDisposable
public string? Rel { get; set; }

/// <summary>
/// The target attribute specifies where to open the link, if Href is specified.
/// Gets or sets the target attribute that specifies where to open the link, if Href is specified.
/// Possible values: _blank | _self | _parent | _top.
/// </summary>
[Parameter]
Expand Down Expand Up @@ -82,6 +82,9 @@ public partial class FluentAnchor : FluentComponentBase, IAsyncDisposable
[Parameter]
public Icon? IconEnd { get; set; }

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

/// <summary>
/// Gets or sets the content to be rendered inside the component.
/// </summary>
Expand All @@ -92,7 +95,9 @@ protected override void OnParametersSet()
{
string[] values = { "_self", "_blank", "_parent", "_top" };
if (!string.IsNullOrEmpty(Target) && !values.Contains(Target))
{
throw new ArgumentException("Target must be one of the following values: _self, _blank, _parent, _top");
}

// If the Href has been specified (as it should) and if starts with '#,'
// we assume the rest of the value contains the id of the element the link points to.
Expand All @@ -105,7 +110,7 @@ protected override void OnParametersSet()
// https://github.com/WICG/scroll-to-text-fragment/

_targetId = Href[1..];
int index = _targetId.IndexOf(":~:", StringComparison.Ordinal);
var index = _targetId.IndexOf(":~:", StringComparison.Ordinal);
if (index > 0)
{
_targetId = _targetId[..index];
Expand All @@ -130,6 +135,10 @@ private async Task OnClickAsync()
// If the target ID has been specified, we know this is an anchor link that we need to scroll to
await _jsModule.InvokeVoidAsync("scrollIntoView", _targetId);
}
if (OnClick.HasDelegate)
{
await OnClick.InvokeAsync();
}
}

/// <inheritdoc />
Expand Down

0 comments on commit 3281163

Please sign in to comment.