Skip to content

Conversation

@imbansalaniket
Copy link

@imbansalaniket imbansalaniket commented Apr 21, 2025

Description

This pull request adds support for moving grid items when drag events are initiated from elements outside the grid. This enhancement allows developers to implement more interactive interfaces, such as custom drag handles or external controls that reposition grid items without direct interaction with the grid itself.

A specific scenario motivating this enhancement involves grid item titles that are displayed as popups when hovering over a grid item. These popup elements are appended to the HTML body (or a similar general DOM container) as per standard best practices for creating tooltips or popups, ensuring proper rendering and positioning. Since these popups exist outside the grid item’s DOM hierarchy, they cannot inherently trigger grid item movement.

To address this limitation, the grid’s drag-and-drop functionality has been extended to support external elements. This feature allows developers to dynamically reference and use such external elements (e.g., popup titles) as drag handles for moving grid items.

This solution leverages existing drag-and-drop infrastructure, ensuring seamless integration without introducing additional complexity.

A new demo, "Title Drag from Outside GridStack Item", has been added to illustrate this use case and demonstrate the versatility of this enhancement.

ExternalTitleDrag

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

@imbansalaniket imbansalaniket changed the title Support dragging the grid item from outside the grid item. Support dragging the grid item from external (outside grid) elements. Apr 21, 2025
@imbansalaniket imbansalaniket changed the title Support dragging the grid item from external (outside grid) elements. Support dragging of the grid item from external (outside grid) elements. Apr 21, 2025
@imbansalaniket imbansalaniket changed the title Support dragging of the grid item from external (outside grid) elements. Support moving the grid item on drag event on external (outside grid) elements. Apr 21, 2025
@imbansalaniket imbansalaniket changed the title Support moving the grid item on drag event on external (outside grid) elements. Support moving the grid item on drag event of external (outside grid) elements. Apr 21, 2025
@imbansalaniket imbansalaniket changed the title Support moving the grid item on drag event of external (outside grid) elements. Support Grid Item Movement via External Element (outside Grid) Drag Apr 24, 2025
- `scroll`?: boolean - default to 'true', enable or disable the scroll when an element is dragged on bottom or top of the grid.
- `cancel`?: string - prevents dragging from starting on specified elements, listed as comma separated selectors (eg: '.no-drag'). default built in is 'input,textarea,button,select,option'
- `helper`?: 'clone' | ((el: HTMLElement) => HTMLElement) - helper function when dragging side panel items that need to be cloned before dropping (ex: 'clone' or your own method)
- `dragElements`?: HTMLElement[] - references to the elements (outside the grid item) to be used for dragging grid item
Copy link
Member

Choose a reason for hiding this comment

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

honestly this wouldn't work in general since you assume a fix set of elements (really a single one shared in your case) which doesn't work for dynamic elements. what happens when you add/remove/reparent items ?

@adumesny
Copy link
Member

adumesny commented May 4, 2025

not sure I understand why you need to be 'outside' the grid. you can use CSS to position you drag handle (and show/hide on mouse over like we do for resize handles) and still be per item and inside each grid - beside your showing the issue of the tab not moving along either (and disapearing) which isn't great.

Thanks for the effort but I cannot take this - see my other comments as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants