[FluentKeyCodeProvider] Add a global service to capture keystrokes #1740
+745
−140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a global service to capture keystrokes
Section
In some circumstances, Blazor does not retrieve all the
KeyDown
information received from JavaScript.FluentKeyCode
retrieves this data, in a similar way to the JavaScript KeyCode library and to this demo sample.The
FluentKeyCode
component extends the functionality ofOnKeyDown
by adding theKeyCode
property when theOnKeyDown
event is raised.👉 Global
You can also capture keystrokes globally on the current page. To do this, we provide you with a
IKeyCodeService
injected by theAddFluentUIComponents
method. Add the following component at the end of yourMainLayout.razor
file.<FluentKeyCodeProvider />
Once the provider and service have been injected, you can:
Retrieve the service and register the method that will capture the keys:
Implement the interface
IKeyCodeListener
, retrieve the service and register the method that will capture the keys:Some keystrokes are used by the browser (e.g.
Ctrl + A
). You can disable this function using thePreventDefault
attribute with theFluentKeyCodeProvider
component.Unit Tests
KeyDownHandler
)