Skip to content
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

Fix #6998: add closest check condition to detect handle icon drag. #7051

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

KumJungMin
Copy link
Contributor

@KumJungMin KumJungMin commented Aug 15, 2024

Defect Fixes

Cause

  • In the dataTable, handle drag sometimes does not trigger.
  • This issue occurs when the mousedown event is fired on the handle, and the event.target is a child element (e.g., <path>) of the icon.

In the video, you can see in the console that sorting fails to work when event.target is a <path> element.

2024-08-15.1.52.29.mp4

Solution

  • To determine if the handle is being used, the closest(mdn docs) function is employed to check if the parent element of event.target is the handle element.
  • This allows sorting to occur even if a child element (e.g., <path>) within the icon is selected, as long as the parent element is the handle.

fixed example

222.mp4

Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Aug 15, 2024 3:09pm
primereact-v9 ⬜️ Ignored (Inspect) Visit Preview Aug 15, 2024 3:09pm

Copy link

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@KumJungMin KumJungMin marked this pull request as ready for review August 15, 2024 05:03
@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Aug 15, 2024
@melloware
Copy link
Member

melloware commented Aug 15, 2024

Fantastic debugging! Can you try this one to see if it can be simplified logic...

const isDragHandle = isUnstyled()
    ? DomHandler.getAttribute(event.target, 'data-pc-section') === 'rowreordericon' || event.target.closest('[data-pc-section="rowreordericon"]')
    : DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle') || event.target.closest('.p-datatable-reorderablerow-handle');

event.currentTarget.draggable = isDragHandle;
event.target.draggable = !isDragHandle;

@melloware melloware self-requested a review August 15, 2024 11:18
@melloware melloware self-assigned this Aug 15, 2024
@nitrogenous nitrogenous self-requested a review August 15, 2024 12:54
@KumJungMin
Copy link
Contributor Author

Fantastic debugging! Can you try this one to see if it can be simplified logic...

const isDragHandle = isUnstyled()
    ? DomHandler.getAttribute(event.target, 'data-pc-section') === 'rowreordericon' || event.target.closest('[data-pc-section="rowreordericon"]')
    : DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle') || event.target.closest('.p-datatable-reorderablerow-handle');

event.currentTarget.draggable = isDragHandle;
event.target.draggable = !isDragHandle;

thank you for suggestion :) i modified it
(4cc6866)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataTable: Sometimes row reordering just doesn't work.
2 participants