Can `OnClick` become `@onclick`?
DanGould opened this issue · comments
Dan Gould commented
In the demo I see you're using OnClick
on IonButton
for example. Can the EventHandler from @onclick
serve that purpose so that there is one standard interface? What would need to change?
Andrew Camilleri commented
OnClick
adds some additional functionality, notably navigating internally when a relative href
attribute is provided:
protected bool ShouldInterceptHref => InputAttributes != null && (InputAttributes.ContainsKey("href") &&
(!InputAttributes.TryGetValue("target",
out var target) ||
target.ToString().ToLowerInvariant()
.TrimStart('_') == "self"));
protected async Task OnClickCallback(MouseEventArgs obj)
{
if (ShouldInterceptHref)
{
NavigationManager.NavigateTo(InputAttributes["href"].ToString());
}
else
{
await OnClick.InvokeAsync(obj);
}
}
You don't need to use it, but I would advise against it to avoid glitches