Skip to content

fix: allow fileupload drag and drop in edit mode on full component without triggering file picker #5889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025

Conversation

alpetric
Copy link
Collaborator

@alpetric alpetric commented Jun 5, 2025

not sure if there is a better way as MoveResize captures all events


Important

Prevents file picker from triggering during drag events in FileInput.svelte by checking pointer movement before allowing click events.

  • Behavior:
    • Prevents file picker from triggering on drag events by tracking pointer start positions (pointerStartX, pointerStartY) and checking movement in on:click event.
    • If movement exceeds 5 pixels in any direction, the click event is prevented.
  • Functions:
    • Adds handlePointerDown() to record initial pointer positions.
    • Modifies on:click event handler to include movement check logic.

This description was created by Ellipsis for a0c4807. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to afef4ae in 1 minute and 27 seconds. Click for details.
  • Reviewed 57 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. frontend/src/lib/components/common/fileInput/FileInput.svelte:34
  • Draft comment:
    Consider using pointer capture (e.g. event.target.setPointerCapture(e.pointerId)) in handlePointerDown for more robust tracking when the pointer leaves the element.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
2. frontend/src/lib/components/common/fileInput/FileInput.svelte:208
  • Draft comment:
    Consider adding a pointerup handler to release pointer capture and reset hasMoved, ensuring the state isn’t left inconsistent if the user releases outside the element.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
3. frontend/src/lib/components/common/fileInput/FileInput.svelte:210
  • Draft comment:
    Consider moving the inline on:click callback into a named function for improved clarity and maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_hJZh11Br2IMWGNnF

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

cloudflare-workers-and-pages bot commented Jun 5, 2025

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: a0c4807
Status: ✅  Deploy successful!
Preview URL: https://733dd932.windmill.pages.dev
Branch Preview URL: https://alp-app-file-input-dnd.windmill.pages.dev

View logs

Comment on lines 40 to 46
function handlePointerMove(e: PointerEvent) {
const deltaX = Math.abs(e.clientX - pointerStartX)
const deltaY = Math.abs(e.clientY - pointerStartY)
if (deltaX > 5 || deltaY > 5) {
hasMoved = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just compute that on click instead of on every move event

Comment on lines +33 to +36
function handlePointerDown(e: PointerEvent) {
pointerStartX = e.clientX
pointerStartY = e.clientY
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation tracks the pointer start position but doesn't continuously monitor movement during drag operations. For proper drag detection, consider adding:

  1. A hasMoved boolean flag to track whether movement has occurred
  2. A handlePointerMove function to update this flag when movement exceeds the threshold
  3. The corresponding on:pointermove event listener on the button element

This would make the drag detection more reliable and match the logic in the click handler that's checking for movement.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed a0c4807 in 1 minute and 28 seconds. Click for details.
  • Reviewed 43 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. frontend/src/lib/components/common/fileInput/FileInput.svelte:200
  • Draft comment:
    Extract the drag threshold (currently 5) into a named constant (e.g., DRAG_THRESHOLD) for improved clarity and easier future adjustments.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. frontend/src/lib/components/common/fileInput/FileInput.svelte:199
  • Draft comment:
    The click handler uses pointer coordinates (e.clientX/clientY) to decide if the event should be suppressed. This may not be reliable for non-pointer (e.g., keyboard-initiated) clicks. Consider adding a fallback or guard to ensure accessibility.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. frontend/src/lib/components/common/fileInput/FileInput.svelte:206
  • Draft comment:
    Removal of the pointermove handler and the 'hasMoved' flag simplifies the code. Verify that this change doesn’t inadvertently block valid click events in cases of slight pointer movement.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None

Workflow ID: wflow_8Rl72YfDH6VsRLRf

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@rubenfiszel rubenfiszel merged commit 9ae3212 into main Jun 5, 2025
16 checks passed
@rubenfiszel rubenfiszel deleted the alp/app_file_input_dnd branch June 5, 2025 21:52
@github-actions github-actions bot locked and limited conversation to collaborators Jun 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants