bito-code-review[bot] commented on PR #42009:
URL: https://github.com/apache/superset/pull/42009#issuecomment-4961801770

   <!-- Bito Reply -->
   The flagged issue is correct. The `handleKeyboardActivation` utility, as 
implemented in this PR, does not guard against an `undefined` callback. When 
`onClick` is optional and not provided, `handleKeyboardActivation(undefined)` 
will throw a `TypeError` when a user presses Enter or Space on the element.
   
   To resolve this, you should update the `handleKeyboardActivation` utility to 
check if the callback exists before invoking it, or ensure that the components 
using it only pass a valid callback. Given the pattern used in other files in 
this PR (e.g., `ActionButton/index.tsx` and `PopoverSection/index.tsx`), 
guarding the call is the most robust approach.
   
   ### Proposed Fix for `handleKeyboardActivation.ts`
   
   ```typescript
   export function handleKeyboardActivation(
     callback?: (event: KeyboardEvent) => void,
   ) {
     return (event: KeyboardEvent) => {
       if ((event.key === 'Enter' || event.key === ' ') && callback) {
         event.preventDefault();
         callback(event);
       }
     };
   }
   ```
   
   I have checked the PR comments and there are no other review comments to 
address. Would you like me to implement this fix for you?
   
   
**superset-frontend/packages/superset-ui-core/src/utils/handleKeyboardActivation.ts**
   ```
   export function handleKeyboardActivation(
     callback?: (event: KeyboardEvent) => void,
   ) {
     return (event: KeyboardEvent) => {
       if ((event.key === 'Enter' || event.key === ' ') && callback) {
         event.preventDefault();
         callback(event);
       }
     };
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to