Skip to content

Commit aafb081

Browse files
committed
Rename DOM types and change namespace
Fixes: #12553 This change renames all of our browser/DOM specific types from `UIFooEventArgs` to `FooEventArgs` and puts the in the `.Web` namespace. In addition to this, we're moving `EventHandlers` and `BindAttributes` to the same. This has the impact of scoping the mappings those classes provide based on the `.Web` namespace. This means that we now expect `.Web` to be present as a using in basically all contexts for a browser-based Blazor app. Updated templates, samples and tests. I'll also need to update about a million tests in the compiler codebase. I've logged dotnet/AspNetCore.Docs#13832 to track the docs and release notes part of this work.
1 parent 3b51b55 commit aafb081

File tree

51 files changed

+855
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+855
-817
lines changed

src/Components/Blazor/Build/test/BindRazorIntegrationTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public void Render_BuiltIn_BindToInputWithoutType_WritesAttributes()
271271
{
272272
// Arrange
273273
var component = CompileToComponent(@"
274+
@using Microsoft.AspNetCore.Components.Web
274275
<input @bind=""@ParentValue"" />
275276
@code {
276277
public int ParentValue { get; set; } = 42;
@@ -292,6 +293,7 @@ public void Render_BuiltIn_BindToInputText_WithFormat_WritesAttributes()
292293
{
293294
// Arrange
294295
var component = CompileToComponent(@"
296+
@using Microsoft.AspNetCore.Components.Web
295297
<input type=""text"" @bind=""@CurrentDate"" @bind:format=""MM/dd/yyyy""/>
296298
@code {
297299
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
@@ -314,6 +316,7 @@ public void Render_BuiltIn_BindToInputText_WithFormatFromProperty_WritesAttribut
314316
{
315317
// Arrange
316318
var component = CompileToComponent(@"
319+
@using Microsoft.AspNetCore.Components.Web
317320
<input type=""text"" @bind=""@CurrentDate"" @bind:format=""@Format""/>
318321
@code {
319322
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
@@ -338,6 +341,7 @@ public void Render_BuiltIn_BindToInputText_WritesAttributes()
338341
{
339342
// Arrange
340343
var component = CompileToComponent(@"
344+
@using Microsoft.AspNetCore.Components.Web
341345
<input type=""text"" @bind=""@ParentValue"" />
342346
@code {
343347
public int ParentValue { get; set; } = 42;
@@ -360,6 +364,7 @@ public void Render_BuiltIn_BindToInputCheckbox_WritesAttributes()
360364
{
361365
// Arrange
362366
var component = CompileToComponent(@"
367+
@using Microsoft.AspNetCore.Components.Web
363368
<input type=""checkbox"" @bind=""@Enabled"" />
364369
@code {
365370
public bool Enabled { get; set; }

src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Components;
77
using Microsoft.AspNetCore.Components.RenderTree;
88
using Microsoft.AspNetCore.Components.Test.Helpers;
9+
using Microsoft.AspNetCore.Components.Web;
910
using Xunit;
1011
using Xunit.Abstractions;
1112

@@ -202,23 +203,25 @@ public void Render_ChildComponent_WithEventHandler(string expression)
202203
AdditionalSyntaxTrees.Add(Parse(@"
203204
using System;
204205
using Microsoft.AspNetCore.Components;
206+
using Microsoft.AspNetCore.Components.Web;
205207
206208
namespace Test
207209
{
208210
public class MyComponent : ComponentBase
209211
{
210212
[Parameter]
211-
public Action<UIMouseEventArgs> OnClick { get; set; }
213+
public Action<MouseEventArgs> OnClick { get; set; }
212214
}
213215
}
214216
"));
215217

216218
var component = CompileToComponent($@"
219+
@using Microsoft.AspNetCore.Components.Web
217220
<MyComponent OnClick=""{expression}""/>
218221
219222
@code {{
220223
private int counter;
221-
private void Increment(UIMouseEventArgs e) {{
224+
private void Increment(MouseEventArgs e) {{
222225
counter++;
223226
}}
224227
}}");
@@ -235,7 +238,7 @@ private void Increment(UIMouseEventArgs e) {{
235238
AssertFrame.Attribute(frame, "OnClick", 1);
236239

237240
// The handler will have been assigned to a lambda
238-
var handler = Assert.IsType<Action<UIMouseEventArgs>>(frame.AttributeValue);
241+
var handler = Assert.IsType<Action<MouseEventArgs>>(frame.AttributeValue);
239242
Assert.Equal("Test.TestComponent", handler.Target.GetType().FullName);
240243
});
241244
}
@@ -445,11 +448,12 @@ public void Regression_784()
445448

446449
// Act
447450
var component = CompileToComponent(@"
451+
@using Microsoft.AspNetCore.Components.Web
448452
<p @onmouseover=""OnComponentHover"" style=""background: @ParentBgColor;"" />
449453
@code {
450454
public string ParentBgColor { get; set; } = ""#FFFFFF"";
451455
452-
public void OnComponentHover(UIMouseEventArgs e)
456+
public void OnComponentHover(MouseEventArgs e)
453457
{
454458
}
455459
}

src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Components;
88
using Microsoft.AspNetCore.Components.RenderTree;
99
using Microsoft.AspNetCore.Components.Test.Helpers;
10+
using Microsoft.AspNetCore.Components.Web;
1011
using Xunit;
1112
using Xunit.Abstractions;
1213

@@ -308,11 +309,12 @@ public void SupportsUsingStatements()
308309
public async Task SupportsTwoWayBindingForTextboxes()
309310
{
310311
// Arrange/Act
311-
var component = CompileToComponent(
312-
@"<input @bind=""MyValue"" />
313-
@code {
314-
public string MyValue { get; set; } = ""Initial value"";
315-
}");
312+
var component = CompileToComponent(@"
313+
@using Microsoft.AspNetCore.Components.Web
314+
<input @bind=""MyValue"" />
315+
@code {
316+
public string MyValue { get; set; } = ""Initial value"";
317+
}");
316318
var myValueProperty = component.GetType().GetProperty("MyValue");
317319

318320
var renderer = new TestRenderer();
@@ -343,11 +345,12 @@ public async Task SupportsTwoWayBindingForTextboxes()
343345
public async Task SupportsTwoWayBindingForTextareas()
344346
{
345347
// Arrange/Act
346-
var component = CompileToComponent(
347-
@"<textarea @bind=""MyValue"" ></textarea>
348-
@code {
349-
public string MyValue { get; set; } = ""Initial value"";
350-
}");
348+
var component = CompileToComponent(@"
349+
@using Microsoft.AspNetCore.Components.Web
350+
<textarea @bind=""MyValue"" ></textarea>
351+
@code {
352+
public string MyValue { get; set; } = ""Initial value"";
353+
}");
351354
var myValueProperty = component.GetType().GetProperty("MyValue");
352355

353356
var renderer = new TestRenderer();
@@ -378,11 +381,12 @@ public async Task SupportsTwoWayBindingForTextareas()
378381
public async Task SupportsTwoWayBindingForDateValues()
379382
{
380383
// Arrange/Act
381-
var component = CompileToComponent(
382-
@"<input @bind=""MyDate"" />
383-
@code {
384-
public DateTime MyDate { get; set; } = new DateTime(2018, 3, 4, 1, 2, 3);
385-
}");
384+
var component = CompileToComponent(@"
385+
@using Microsoft.AspNetCore.Components.Web
386+
<input @bind=""MyDate"" />
387+
@code {
388+
public DateTime MyDate { get; set; } = new DateTime(2018, 3, 4, 1, 2, 3);
389+
}");
386390
var myDateProperty = component.GetType().GetProperty("MyDate");
387391

388392
var renderer = new TestRenderer();
@@ -416,11 +420,12 @@ public async Task SupportsTwoWayBindingForDateValuesWithFormatString()
416420
{
417421
// Arrange/Act
418422
var testDateFormat = "ddd yyyy-MM-dd";
419-
var component = CompileToComponent(
420-
$@"<input @bind=""@MyDate"" @bind:format=""{testDateFormat}"" />
421-
@code {{
422-
public DateTime MyDate {{ get; set; }} = new DateTime(2018, 3, 4);
423-
}}");
423+
var component = CompileToComponent($@"
424+
@using Microsoft.AspNetCore.Components.Web
425+
<input @bind=""@MyDate"" @bind:format=""{testDateFormat}"" />
426+
@code {{
427+
public DateTime MyDate {{ get; set; }} = new DateTime(2018, 3, 4);
428+
}}");
424429
var myDateProperty = component.GetType().GetProperty("MyDate");
425430

426431
var renderer = new TestRenderer();
@@ -467,6 +472,7 @@ public void SupportsEventHandlerWithLambda()
467472
{
468473
// Arrange
469474
var component = CompileToComponent(@"
475+
@using Microsoft.AspNetCore.Components.Web
470476
<button @onclick=""x => Clicked = true"" />
471477
@code {
472478
public bool Clicked { get; set; }
@@ -486,10 +492,10 @@ public void SupportsEventHandlerWithLambda()
486492
{
487493
AssertFrame.Attribute(frame, "onclick", 1);
488494

489-
var func = Assert.IsType<Action<UIMouseEventArgs>>(frame.AttributeValue);
495+
var func = Assert.IsType<Action<MouseEventArgs>>(frame.AttributeValue);
490496
Assert.False((bool)clicked.GetValue(component));
491497

492-
func(new UIMouseEventArgs());
498+
func(new MouseEventArgs());
493499
Assert.True((bool)clicked.GetValue(component));
494500
});
495501
}
@@ -499,9 +505,10 @@ public void SupportsEventHandlerWithMethodGroup()
499505
{
500506
// Arrange
501507
var component = CompileToComponent(@"
508+
@using Microsoft.AspNetCore.Components.Web
502509
<button @onclick=""OnClick"" />
503510
@code {
504-
public void OnClick(UIMouseEventArgs e) { Clicked = true; }
511+
public void OnClick(MouseEventArgs e) { Clicked = true; }
505512
public bool Clicked { get; set; }
506513
}");
507514

@@ -513,33 +520,34 @@ public void SupportsEventHandlerWithMethodGroup()
513520
var frames = GetRenderTree(renderer, component);
514521

515522
// Assert
516-
Action<UIMouseEventArgs> func = default; // Since this is a method group, we don't need to create an EventCallback
523+
Action<MouseEventArgs> func = default; // Since this is a method group, we don't need to create an EventCallback
517524
Assert.Collection(
518525
frames,
519526
frame => AssertFrame.Element(frame, "button", 2, 0),
520527
frame =>
521528
{
522529
AssertFrame.Attribute(frame, "onclick", 1);
523530

524-
func = Assert.IsType<Action<UIMouseEventArgs>>(frame.AttributeValue);
531+
func = Assert.IsType<Action<MouseEventArgs>>(frame.AttributeValue);
525532
Assert.False((bool)clicked.GetValue(component));
526533

527534

528535
});
529536

530-
func.Invoke(new UIMouseEventArgs());
537+
func.Invoke(new MouseEventArgs());
531538
Assert.True((bool)clicked.GetValue(component));
532539
}
533540

534541
[Fact]
535542
public async Task SupportsTwoWayBindingForBoolValues()
536543
{
537544
// Arrange/Act
538-
var component = CompileToComponent(
539-
@"<input @bind=""MyValue"" />
540-
@code {
541-
public bool MyValue { get; set; } = true;
542-
}");
545+
var component = CompileToComponent(@"
546+
@using Microsoft.AspNetCore.Components.Web
547+
<input @bind=""MyValue"" />
548+
@code {
549+
public bool MyValue { get; set; } = true;
550+
}");
543551
var myValueProperty = component.GetType().GetProperty("MyValue");
544552

545553
var renderer = new TestRenderer();
@@ -571,11 +579,12 @@ public async Task SupportsTwoWayBindingForEnumValues()
571579
{
572580
// Arrange/Act
573581
var myEnumType = FullTypeName<MyEnum>();
574-
var component = CompileToComponent(
575-
$@"<input @bind=""MyValue"" />
576-
@code {{
577-
public {myEnumType} MyValue {{ get; set; }} = {myEnumType}.{nameof(MyEnum.FirstValue)};
578-
}}");
582+
var component = CompileToComponent($@"
583+
@using Microsoft.AspNetCore.Components.Web
584+
<input @bind=""MyValue"" />
585+
@code {{
586+
public {myEnumType} MyValue {{ get; set; }} = {myEnumType}.{nameof(MyEnum.FirstValue)};
587+
}}");
579588
var myValueProperty = component.GetType().GetProperty("MyValue");
580589

581590
var renderer = new TestRenderer();

src/Components/Blazor/Templates/src/content/BlazorWasm-CSharp/Client/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@using System.Net.Http
22
@using Microsoft.AspNetCore.Components.Forms
33
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
45
@using Microsoft.JSInterop
56
@*#if (!Hosted)
67
@using BlazorWasm_CSharp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@using Microsoft.AspNetCore.Components.Web
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using System.Net.Http
22
@using Microsoft.AspNetCore.Components.Routing
3+
@using Microsoft.AspNetCore.Components.Web
34
@using Microsoft.JSInterop
45
@using Microsoft.AspNetCore.Blazor.E2EPerformance
56
@using Microsoft.AspNetCore.Blazor.E2EPerformance.Shared
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using System.Net.Http
1+
@using System.Net.Http
22
@using Microsoft.AspNetCore.Components.Routing
3+
@using Microsoft.AspNetCore.Components.Web
34
@using StandaloneApp
45
@using StandaloneApp.Shared

src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp3.0.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public static partial class BindConverter
5050
public static bool TryConvertToString(object obj, System.Globalization.CultureInfo culture, out string value) { throw null; }
5151
public static bool TryConvertTo<T>(object obj, System.Globalization.CultureInfo culture, out T value) { throw null; }
5252
}
53+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
54+
public sealed partial class BindElementAttribute : System.Attribute
55+
{
56+
public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute) { }
57+
public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
58+
public string Element { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
59+
public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
60+
public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
61+
}
5362
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
5463
public sealed partial class CascadingParameterAttribute : System.Attribute
5564
{
@@ -192,6 +201,13 @@ public readonly partial struct EventCallback<TValue>
192201
public bool HasDelegate { get { throw null; } }
193202
public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; }
194203
}
204+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
205+
public sealed partial class EventHandlerAttribute : System.Attribute
206+
{
207+
public EventHandlerAttribute(string attributeName, System.Type eventArgsType) { }
208+
public string AttributeName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
209+
public System.Type EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
210+
}
195211
public partial interface IComponent
196212
{
197213
void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle);

src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public static partial class BindConverter
5050
public static bool TryConvertToString(object obj, System.Globalization.CultureInfo culture, out string value) { throw null; }
5151
public static bool TryConvertTo<T>(object obj, System.Globalization.CultureInfo culture, out T value) { throw null; }
5252
}
53+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
54+
public sealed partial class BindElementAttribute : System.Attribute
55+
{
56+
public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute) { }
57+
public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
58+
public string Element { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
59+
public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
60+
public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
61+
}
5362
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
5463
public sealed partial class CascadingParameterAttribute : System.Attribute
5564
{
@@ -192,6 +201,13 @@ public readonly partial struct EventCallback<TValue>
192201
public bool HasDelegate { get { throw null; } }
193202
public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; }
194203
}
204+
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
205+
public sealed partial class EventHandlerAttribute : System.Attribute
206+
{
207+
public EventHandlerAttribute(string attributeName, System.Type eventArgsType) { }
208+
public string AttributeName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
209+
public System.Type EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
210+
}
195211
public partial interface IComponent
196212
{
197213
void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle);

src/Components/Shared/src/WebEventData.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ private static EventArgs ParseEventArgsJson(ulong eventHandlerId, string eventAr
6060
return eventArgsType switch
6161
{
6262
"change" => DeserializeChangeEventArgs(eventArgsJson),
63-
"clipboard" => Deserialize<UIClipboardEventArgs>(eventArgsJson),
64-
"drag" => Deserialize<UIDragEventArgs>(eventArgsJson),
65-
"error" => Deserialize<UIErrorEventArgs>(eventArgsJson),
66-
"focus" => Deserialize<UIFocusEventArgs>(eventArgsJson),
67-
"keyboard" => Deserialize<UIKeyboardEventArgs>(eventArgsJson),
68-
"mouse" => Deserialize<UIMouseEventArgs>(eventArgsJson),
69-
"pointer" => Deserialize<UIPointerEventArgs>(eventArgsJson),
70-
"progress" => Deserialize<UIProgressEventArgs>(eventArgsJson),
71-
"touch" => Deserialize<UITouchEventArgs>(eventArgsJson),
63+
"clipboard" => Deserialize<ClipboardEventArgs>(eventArgsJson),
64+
"drag" => Deserialize<DragEventArgs>(eventArgsJson),
65+
"error" => Deserialize<ErrorEventArgs>(eventArgsJson),
66+
"focus" => Deserialize<FocusEventArgs>(eventArgsJson),
67+
"keyboard" => Deserialize<KeyboardEventArgs>(eventArgsJson),
68+
"mouse" => Deserialize<MouseEventArgs>(eventArgsJson),
69+
"pointer" => Deserialize<PointerEventArgs>(eventArgsJson),
70+
"progress" => Deserialize<ProgressEventArgs>(eventArgsJson),
71+
"touch" => Deserialize<TouchEventArgs>(eventArgsJson),
7272
"unknown" => EventArgs.Empty,
73-
"wheel" => Deserialize<UIWheelEventArgs>(eventArgsJson),
73+
"wheel" => Deserialize<WheelEventArgs>(eventArgsJson),
7474
_ => throw new InvalidOperationException($"Unsupported event type '{eventArgsType}'. EventId: '{eventHandlerId}'."),
7575
};
7676
}

0 commit comments

Comments
 (0)