Skip to content

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

Merged
Denis Voituron (dvoituron) merged 3 commits into
microsoft:devfrom
oONoobMasterOo:feat/keycode-provider-filters
Oct 21, 2026
Merged

Denis Voituron (dvoituron) merged 3 commits into
microsoft:devfrom
oONoobMasterOo:feat/keycode-provider-filters

Conversation

@oONoobMasterOo

@oONoobMasterOo NoobMaster (oONoobMasterOo) commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

📖 Description

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.

🎫 Issues

👩‍💻 Reviewer Notes

The provider passes the new parameters to its global FluentKeyCode, which already supports them.

📑 Test Plan

Unit tests

Added FluentKeyCode_Provider_PassesKeyFilters.

  • Full tests/Core suite on this branch: 4904 tests, 0 failed (at 64bf1d048).

Other checks

  • Before / after video: see the comment with the recordings below.

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

AI contribution declaration

AI assistance is allowed; fully AI-generated or autonomous pull requests without meaningful human review are not accepted. See the AI contribution policy.

  • I have read and followed the AI contribution policy.
  • I have personally reviewed and understood all changes, tested them, and take responsibility for this contribution.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

None.

…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
Contributor 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

@dvoituron

Copy link
Copy Markdown
Collaborator

We've added a new requirement regarding PRs

@oONoobMasterOo

Copy link
Copy Markdown
Contributor Author

We've added a new requirement regarding PRs

Done

@dvoituron Denis Voituron (dvoituron) removed the Generated by AI Content generated or significantly assisted by AI. label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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