codeant-ai-for-open-source[bot] commented on code in PR #36889:
URL: https://github.com/apache/superset/pull/36889#discussion_r2657541770
##########
superset-frontend/src/dashboard/components/gridComponents/TabsRenderer/TabsRenderer.tsx:
##########
@@ -37,6 +37,36 @@ import {
useSensor,
closestCenter,
} from '@dnd-kit/core';
+
+const isInteractiveElement = (element: HTMLElement | null): boolean => {
+ if (!element) return false;
+ const tagName = element.tagName.toUpperCase();
+ if (
+ tagName === 'INPUT' ||
+ tagName === 'TEXTAREA' ||
+ element.isContentEditable
+ ) {
+ return true;
+ }
+ return isInteractiveElement(element.parentElement);
+};
+
+PointerSensor.activators = [
+ {
+ eventName: 'onPointerDown' as const,
+ handler: ({ nativeEvent: event }, { onActivation }) => {
+ if (
+ event.button !== 0 ||
+ isInteractiveElement(event.target as HTMLElement)
+ ) {
+ return false;
+ }
+ onActivation?.({ event });
Review Comment:
**Suggestion:** The custom `PointerSensor.activators` handler calls
`onActivation` directly on pointer down whenever the conditions pass, which
bypasses the configured `activationConstraint: { distance: 10 }` on the sensor;
this means drags will start immediately instead of after the intended movement
threshold, causing unintended drags when users just click tabs. [logic error]
**Severity Level:** Minor ⚠️
```suggestion
handler: ({ nativeEvent: event }) => {
if (
event.button !== 0 ||
isInteractiveElement(event.target as HTMLElement)
) {
return false;
}
// Returning true lets the default PointerSensor logic
// (including activationConstraint) decide when to activate
```
<details>
<summary><b>Why it matters? ⭐ </b></summary>
The current activator explicitly calls onActivation on pointer down which
forces immediate activation and indeed bypasses the PointerSensor's
activationConstraint (distance: 10) supplied when creating the sensor. In
dnd-kit the handler should return true to indicate the event is a potential
activation and let the sensor's own logic (including distance threshold) decide
when to call onActivation. The suggested change fixes a real logic bug that
causes accidental drags when clicking tabs.
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/components/gridComponents/TabsRenderer/TabsRenderer.tsx
**Line:** 57:64
**Comment:**
*Logic Error: The custom `PointerSensor.activators` handler calls
`onActivation` directly on pointer down whenever the conditions pass, which
bypasses the configured `activationConstraint: { distance: 10 }` on the sensor;
this means drags will start immediately instead of after the intended movement
threshold, causing unintended drags when users just click tabs.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
```
</details>
--
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]