Skip to content

[KeyCode] Add Only, Ignore and PreventDefaultOnly to FluentKeyCodeProvider - #5477

Open
NoobMaster (oONoobMasterOo) wants to merge 1 commit into
microsoft:devfrom
oONoobMasterOo:feat/keycode-provider-filters
Open

NoobMaster (oONoobMasterOo) wants to merge 1 commit into
microsoft:devfrom
oONoobMasterOo:feat/keycode-provider-filters

Conversation

@oONoobMasterOo

Copy link
Copy Markdown

Fixes #4519

FluentKeyCodeProvider only exposed PreventDefault, which prevents the default action of every key, including the Esc key used to close dialogs. It now also exposes the filters already supported by FluentKeyCode, and passes them to its global FluentKeyCode:

  • PreventDefaultOnly: prevent the default action for some keys only.
  • Only: listen to these keys only.
  • Ignore: ignore these keys.
<FluentKeyCodeProvider PreventDefaultOnly="@(new[] { KeyCode.KeyS })" />

The issue also suggests passing these options to KeyCodeService.RegisterListener. That's not possible for PreventDefault: the default action must be prevented synchronously in the browser, before the listeners registered on the server are called. So the options are set on the provider, like PreventDefault today.

Unit Tests

Added FluentKeyCode_Provider_PassesKeyFilters.

…deProvider

The global provider only exposed PreventDefault, which prevents every
browser shortcut, including the Escape key used to close dialogs. The
filters supported by FluentKeyCode are now available on the provider.

Fixes microsoft#4519

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes reuse existing filtering behavior, include regression coverage, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

Exposes existing key filters through FluentKeyCodeProvider, enabling selective global keyboard handling for #4519.

Changes:

  • Adds Only, Ignore, and PreventDefaultOnly parameters and forwards them to FluentKeyCode.
  • Adds regression coverage for all three filters.
File Description
tests/​Core/​Components/​KeyCode/​FluentKeyCodeTests.razor Verifies filter values reach JavaScript registration.
src/​Core/​Components/​KeyCode/​FluentKeyCodeProvider.razor.cs Declares the three provider parameters.
src/​Core/​Components/​KeyCode/​FluentKeyCodeProvider.razor Forwards filters to the global component.

Review effort: Balanced

@dvoituron Denis Voituron (dvoituron) added the Generated by AI Content generated or significantly assisted by AI. label Oct 19, 2026
@dvoituron

Copy link
Copy Markdown
Collaborator

Could you please provide a short video showing the issue before the code change, and then the expected behavior after the fix? This will make it easier to clearly see and validate the improvement.
(You can use “Peek - Screen Recorder,” a free tool, to do this)

@oONoobMasterOo

Copy link
Copy Markdown
Author

Before (dev): to block F5 with the global provider, the only option is <FluentKeyCodeProvider PreventDefault="true" />. F5 is blocked, but typing in the text input is blocked too, since the default action of every key is prevented.

5477-before.mp4

After (this PR): <FluentKeyCodeProvider PreventDefaultOnly="@(new[] { KeyCode.Function5 })" /> blocks F5 only, and typing in the text input works.

5477-after.mp4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Generated by AI Content generated or significantly assisted by AI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add Ignore and Only and PreventDefault parameters to global FluentKeyProvider

3 participants