KeyInterceptorService: Allow omitting TargetClass to attach event handlers to element itself#12377
Conversation
KeyInterceptorOptions.TargetClass to attach event handlers to element itselfThere was a problem hiding this comment.
Pull request overview
This PR enhances the KeyInterceptorService to allow attaching event handlers directly to the subscribed element itself, rather than requiring attachment to child elements with a specific CSS class. This is achieved by making the TargetClass property nullable and handling the null case appropriately.
Key Changes:
- Made
KeyInterceptorOptions.TargetClassnullable to support attaching handlers to the element itself - Updated JavaScript logic to conditionally attach handlers based on whether
TargetClassis null or defined - Added a new constructor overload for
KeyInterceptorOptionsthat accepts only key options (defaultingTargetClassto null)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/MudBlazor/TScripts/mudKeyInterceptor.js | Removed validation requiring targetClass and added conditional logic to attach handlers to the element itself when targetClass is null |
| src/MudBlazor/Services/KeyInterceptor/KeyInterceptorOptions.cs | Made TargetClass nullable, added sealed modifier to class, created new constructor overload accepting only key options, and updated documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Looks good, just one question, we won't have any problems here when it's null? MudBlazor/src/MudBlazor/TScripts/mudKeyInterceptor.js Lines 138 to 149 in 1fb2190 |
|
Guess I was cutting corners a bit with my testing. |
… to attach the handlers to the element itself
1fb2190 to
fd50146
Compare
Will not be a problem, but could be improved upon, see #12380. |
Accept
KeyInterceptorOptions.TargetClassbeingnullto allow for attaching the key event handlers to the subscribed element itself instead of having to attach it to child elements having some class.For context, I want to stop propagation for the keydowns that I'm interested in, but let events for other keys bubble up. As far as i know, this is not possible without JS interop. This service provides exactly that functionality, except for it not being possible to simply attach to the subscribed element itself.
Checklist: