Skip to content

Clarify intentions for dynamic preventDefault #48193

@SteveSandersonMS

Description

@SteveSandersonMS

In dotnet/AspNetCore.Docs#28692, @LunicLynx pointed out a behavior that I did not realise we had. In WebAssembly, it's possible to vary a @onsomeevent:preventDefault flag while that event handler is running, and it happens to produce exactly the behavior people would want.

For example, you can dynamically block specific keystrokes using only C# (previously we have told people to add a JS event handler for this): https://blazorrepl.telerik.com/GduTFbPQ31hhoo2926

Given how this looks like an intentional framework feature, people are likely to use and rely on it. So,

  • Either we should retain this functionality, which means we should add E2E tests to guarantee we preserve it, and show it in docs
  • Or, we should explicitly block this (which would be a breaking change)

Note that this functionality is WebAssembly-only. We don't mind having WebAssembly-only features, but we prefer it when the failure mode is clearer. For example, giving a compile-time or runtime error if it is used in an unsupported mode. Unfortunately in this case the behavior if you run the same component on Blazor Server really bad. It won't block the keystroke you think it's going to block, but then it does block the next keystroke. This would be a bizarre bug in people's apps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions