Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose OnFocus event on MatButton. Closes #314 #323

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoMatButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@using Microsoft.AspNetCore.Components

<h4 class="mat-subtitle1">Simple use</h4>
<MatButton Icon="favorite" OnClick="@RunOnClick" Label="Simple Button"></MatButton>
<MatButton Icon="favorite" OnClick="@RunOnClick" Label="Simple Button" OnFocus="@RunOnFocus"></MatButton>

<h5 class="mat-subtitle1">With Font-Awsome Icons and Link</h5>
<MatButton Link="https://github.com/BlazorComponents/MatBlazor">
Expand All @@ -24,6 +24,11 @@
JsRuntime.InvokeAsync<object>("window.alert", "Test");
}

public void RunOnFocus(FocusEventArgs e)
{
Console.WriteLine(e.Type);
}

}

</Content>
Expand All @@ -32,7 +37,7 @@
@using Microsoft.AspNetCore.Components

<h4 class=""mat-subtitle1"">Simple use</h4>
<MatButton Icon=""favorite"" OnClick=""@RunOnClick"" Label=""Simple Button""></MatButton>
<MatButton Icon=""favorite"" OnClick=""@RunOnClick"" OnFocus=""@RunOnFocus"" Label=""Simple Button""></MatButton>

<h5 class=""mat-subtitle1"">With Font-Awsome Icons and Link</h5>
<MatButton Link=""https://github.com/BlazorComponents/MatBlazor"">
Expand All @@ -47,6 +52,11 @@
JsRuntime.InvokeAsync<object>(""window.alert"", ""Test"");
}

public void RunOnFocus(FocusEventArgs e)
{
Console.WriteLine(e.Type);
}

}

")></BlazorFiddle>
Expand Down
5 changes: 5 additions & 0 deletions src/MatBlazor.Demo/Doc/DocMatButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<td>EventCallback&lt;MouseEventArgs&gt;</td>
<td>Event occurs when the user clicks on an element.</td>
</tr>
<tr>
<td>OnFocus</td>
<td>EventCallback&lt;FocusEventArgs&gt;</td>
<td>Event occurs when the user focuses on an element.</td>
</tr>
<tr>
<td>OnClickStopPropagation</td>
<td>Boolean</td>
Expand Down
15 changes: 15 additions & 0 deletions src/MatBlazor/Components/MatButton/BaseMatButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public BaseMatButton()
[Parameter]
public bool OnClickStopPropagation { get; set; }

/// <summary>
/// Event occurs when the user focuses on an element
/// </summary>
[Parameter]
public EventCallback<FocusEventArgs> OnFocus { get; set; }

/// <summary>
/// Command executed when the user clicks on an element.
/// </summary>
Expand Down Expand Up @@ -197,6 +203,15 @@ protected void OnClickHandler(MouseEventArgs ev)
}
}

/// <summary>
/// Event handler for focus event
/// </summary>
/// <param name="ev"></param>
protected void OnFocusHandler(FocusEventArgs ev)
{
OnFocus.InvokeAsync(ev);
}

private bool _raised;
private bool _unelevated;
private bool _outlined;
Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor/Components/MatButton/MatButton.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace MatBlazor
@inherits BaseMatButton

<button class="@ClassMapper.AsString()" style="@StyleMapper.AsString()" @onclick="OnClickHandler" @onclick:stopPropagation=@OnClickStopPropagation disabled=@Disabled aria-label="@(Label ?? Icon)" @ref="Ref" type="@Type" name="@Name" value="@Value" @attributes="Attributes" Id="@Id">
<button class="@ClassMapper.AsString()" style="@StyleMapper.AsString()" @onclick="OnClickHandler" @onclick:stopPropagation=@OnClickStopPropagation @onfocus="OnFocusHandler" disabled=@Disabled aria-label="@(Label ?? Icon)" @ref="Ref" type="@Type" name="@Name" value="@Value" @attributes="Attributes" Id="@Id">
<div class="mdc-button__ripple"></div>
@if (Icon != null)
{
Expand Down
11 changes: 11 additions & 0 deletions src/MatBlazor/MatBlazor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.