-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Compiler support for @oneventname:preventDefault and @oneventname:stopPropagation #14517
Comments
- 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
- 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
@SteveSandersonMS I have a question about preventDefault. Is it now possible to preventDefault only for some keys? For example i want to preventDefault on a textfield if the enter key is pressed. In JavaScript I would write it like this: document.getElementById('div').keypress(function (event) {
if (event.which === 13) {
evt.preventDefault();
}
)}; I hope it is legit to ask that here. |
@MarkusRodler For that scenario you would still need to use a JS event handler, since the .NET handlers are async. |
@SteveSandersonMS Thanks for the reply! |
I looked into doing this myself, but after talking with @rynowak, it seems likely that we're missing some support in the compiler for having
@directiveattribute:param
appearing on its own (not alongside@directiveattribute
).The overall summary is:
@oneventname
, there's also@oneventname:preventDefault
and@oneventname:stopPropagation
. These can be used either alongside@oneventname
or independently of it.true
@foo:preventDefault
compiles asbuilder.AddEventPreventDefaultAttribute(sequence, "foo", boolValueExpression)
. This new method is added here.@foo:stopPropagation
compiles asbuilder.AddEventStopPropagationAttribute(sequence, "foo", boolValueExpression)
. This new method is added here.AddAttribute
calls for the element (internally they work by calling intoAddAttribute
).Microsoft.AspNetCore.Components.Web
, since that's where the runtime implementation is, and won't produce compiling code if you haven't referenced that.Examples:
Minimized preventDefault
Generates:
Note that you can also have a regular
@onclick
event handler on the same element, but that's totally independent.Non-minimized preventDefault
Generates:
Note that you can also have a regular
@onclick
event handler on the same element, but that's totally independent.Minimized stopPropagation
Generates:
Note that you can also have a regular
@onkeydown
event handler on the same element, but that's totally independent.Non-minimized stopPropagation
Generates:
Note that you can also have a regular
@onmouseover
event handler on the same element, but that's totally independentlThe text was updated successfully, but these errors were encountered: