Skip to content

Commit 9ca9c74

Browse files
committed
Clean Up JSInvoke
1 parent 4febbab commit 9ca9c74

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

src/MatBlazor.Demo/Demo/DemoMatNavMenu.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<MatNavItem Disabled="true" Href="#">Item 6.A</MatNavItem>
3030
<MatNavItem>Item 6.B</MatNavItem>
3131
<MatNavItem>Item 6.C</MatNavItem>
32-
32+
3333
</MatNavSubMenuList>
3434
</MatNavSubMenu>
35-
<MatNavItem Href="https://blazorboilerplate.com/">Blazor Boilerplate - Href</MatNavItem>
35+
<MatNavItem Href="https://blazorboilerplate.com/" >Blazor Boilerplate - Href</MatNavItem>
3636
<MatNavItem Href="https://www.matblazor.com/">MatBlazor - Href</MatNavItem>
3737
</MatNavMenu>
3838

@@ -312,4 +312,4 @@
312312
}
313313
")></BlazorFiddle>
314314
</SourceContent>
315-
</DemoContainer>
315+
</DemoContainer>

src/MatBlazor/Components/MatButton/BaseMatButton.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Windows.Input;
33
using Microsoft.AspNetCore.Components;
44
using Microsoft.AspNetCore.Components.Web;
5-
using Microsoft.JSInterop;
65

76
namespace MatBlazor
87
{
@@ -15,9 +14,6 @@ public class BaseMatButton : BaseMatDomComponent
1514
[Inject]
1615
public Microsoft.AspNetCore.Components.NavigationManager UriHelper { get; set; }
1716

18-
[Inject]
19-
public IJSRuntime JSRuntime { get; set; }
20-
2117
protected async override Task OnFirstAfterRenderAsync()
2218
{
2319
await base.OnFirstAfterRenderAsync();
@@ -190,13 +186,13 @@ public string Label
190186
[Parameter]
191187
public RenderFragment ChildContent { get; set; }
192188

193-
protected void OnClickHandler(MouseEventArgs ev)
189+
protected async void OnClickHandler(MouseEventArgs ev)
194190
{
195191
if (Link != null)
196192
{
197193
if (!string.IsNullOrEmpty(Target))
198194
{
199-
JSRuntime.InvokeAsync<object>("open", Link, Target);
195+
await JsInvokeAsync<object>("open", Link, Target);
200196
}
201197
else
202198
{
@@ -205,7 +201,7 @@ protected void OnClickHandler(MouseEventArgs ev)
205201
}
206202
else
207203
{
208-
OnClick.InvokeAsync(ev);
204+
await OnClick.InvokeAsync(ev);
209205
if (Command?.CanExecute(CommandParameter) ?? false)
210206
{
211207
Command.Execute(CommandParameter);

src/MatBlazor/Components/MatIconButton/BaseMatIconButton.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Windows.Input;
33
using Microsoft.AspNetCore.Components;
44
using Microsoft.AspNetCore.Components.Web;
5-
using Microsoft.JSInterop;
65

76
namespace MatBlazor
87
{
@@ -14,9 +13,6 @@ public class BaseMatIconButton : BaseMatDomComponent
1413
[Inject]
1514
public Microsoft.AspNetCore.Components.NavigationManager UriHelper { get; set; }
1615

17-
[Inject]
18-
public IJSRuntime JSRuntime { get; set; }
19-
2016
private bool _disabled;
2117
private bool _toggled = false;
2218

@@ -117,7 +113,7 @@ protected async Task OnClickHandler(MouseEventArgs ev)
117113
{
118114
if (!string.IsNullOrEmpty(Target))
119115
{
120-
JSRuntime.InvokeAsync<object>("open", Link, Target);
116+
await JsInvokeAsync<object>("open", Link, Target);
121117
}
122118
else
123119
{
@@ -126,7 +122,7 @@ protected async Task OnClickHandler(MouseEventArgs ev)
126122
}
127123
else
128124
{
129-
OnClick.InvokeAsync(ev);
125+
await OnClick.InvokeAsync(ev);
130126
if (Command?.CanExecute(CommandParameter) ?? false)
131127
{
132128
Command.Execute(CommandParameter);

src/MatBlazor/Components/MatNavMenu/BaseMatNavItem.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Components;
22
using Microsoft.AspNetCore.Components.Routing;
33
using Microsoft.AspNetCore.Components.Web;
4-
using Microsoft.JSInterop;
54
using System.Threading.Tasks;
65
using System.Windows.Input;
76

@@ -15,9 +14,6 @@ public class BaseMatNavItem : BaseMatListItem
1514
[Inject]
1615
public NavigationManager UriHelper { get; set; }
1716

18-
[Inject]
19-
public IJSRuntime JSRuntime { get; set; }
20-
2117
[CascadingParameter]
2218
public BaseMatNavMenu MatNavMenu { get; set; }
2319

@@ -95,14 +91,14 @@ protected async void OnClickHandler(MouseEventArgs e)
9591

9692
if (Href != null)
9793
{
98-
//if (!string.IsNullOrEmpty(Target))
99-
//{
100-
// await JSRuntime.InvokeAsync<object>("open", Href, Target);
101-
//}
102-
//else
103-
//{
94+
if (!string.IsNullOrEmpty(Target))
95+
{
96+
await JsInvokeAsync<object>("open", Href, Target);
97+
}
98+
else
99+
{
104100
UriHelper.NavigateTo(Href);
105-
//}
101+
}
106102
}
107103
else
108104
{

0 commit comments

Comments
 (0)