Skip to content

Commit 5f3037d

Browse files
author
N. Taylor Mullen
committed
Add support for EnableStopPropagation and EnablePreventDefault.
- For our current world Blazor both of these properties are always `true`. However, for other non-web Blazor scenarios the `EventHandler` attributes at that layer will turn off these features because they're specific to web. #14517
1 parent 19718f6 commit 5f3037d

6 files changed

+303
-274
lines changed

src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ public readonly partial struct EventCallback<TValue>
207207
public sealed partial class EventHandlerAttribute : System.Attribute
208208
{
209209
public EventHandlerAttribute(string attributeName, System.Type eventArgsType) { }
210+
public EventHandlerAttribute(string attributeName, System.Type eventArgsType, bool enableStopPropagation, bool enablePreventDefault) { }
210211
public string AttributeName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
212+
public bool EnablePreventDefault { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
213+
public bool EnableStopPropagation { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
211214
public System.Type EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
212215
}
213216
public partial interface IComponent

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ public readonly partial struct EventCallback<TValue>
207207
public sealed partial class EventHandlerAttribute : System.Attribute
208208
{
209209
public EventHandlerAttribute(string attributeName, System.Type eventArgsType) { }
210+
public EventHandlerAttribute(string attributeName, System.Type eventArgsType, bool enableStopPropagation, bool enablePreventDefault) { }
210211
public string AttributeName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
212+
public bool EnablePreventDefault { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
213+
public bool EnableStopPropagation { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
211214
public System.Type EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
212215
}
213216
public partial interface IComponent

src/Components/Components/src/EventHandlerAttribute.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ public sealed class EventHandlerAttribute : Attribute
1616
/// </summary>
1717
/// <param name="attributeName"></param>
1818
/// <param name="eventArgsType"></param>
19-
public EventHandlerAttribute(string attributeName, Type eventArgsType)
19+
public EventHandlerAttribute(string attributeName, Type eventArgsType) : this(attributeName, eventArgsType, false, false)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Constructs an instance of <see cref="EventHandlerAttribute"/>.
25+
/// </summary>
26+
/// <param name="attributeName"></param>
27+
/// <param name="eventArgsType"></param>
28+
/// <param name="enableStopPropagation"></param>
29+
/// <param name="enablePreventDefault"></param>
30+
public EventHandlerAttribute(string attributeName, Type eventArgsType, bool enableStopPropagation, bool enablePreventDefault)
2031
{
2132
if (attributeName == null)
2233
{
@@ -30,6 +41,8 @@ public EventHandlerAttribute(string attributeName, Type eventArgsType)
3041

3142
AttributeName = attributeName;
3243
EventArgsType = eventArgsType;
44+
EnableStopPropagation = enableStopPropagation;
45+
EnablePreventDefault = enablePreventDefault;
3346
}
3447

3548
/// <summary>
@@ -41,5 +54,15 @@ public EventHandlerAttribute(string attributeName, Type eventArgsType)
4154
/// Gets the event argument type.
4255
/// </summary>
4356
public Type EventArgsType { get; }
57+
58+
/// <summary>
59+
/// Gets the event's ability to stop propagation.
60+
/// </summary>
61+
public bool EnableStopPropagation { get; }
62+
63+
/// <summary>
64+
/// Gets the event's ability to prevent default event flow.
65+
/// </summary>
66+
public bool EnablePreventDefault { get; }
4467
}
4568
}

0 commit comments

Comments
 (0)