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

Allow developers to style the dragged item/row #5548

Closed
jouni opened this issue Feb 10, 2023 · 1 comment · Fixed by #7593
Closed

Allow developers to style the dragged item/row #5548

jouni opened this issue Feb 10, 2023 · 1 comment · Fixed by #7593
Assignees
Labels

Comments

@jouni
Copy link
Member

jouni commented Feb 10, 2023

Describe your motivation

In some use cases, it would be ideal to indicate to the end user which item they are dragging, in addition to the "ghost" element that follows the mouse, to let them know the original position from which they started the drag. It might be that there are two identical looking items, and in that case it is impossible to know which item is being dragged.

Describe the solution you'd like

Add a stylable CSS part name for the dragged row and its cells. For example vaadin-grid::part(dragged-row) and vaadin-grid::part(dragged-cell).

Describe alternatives you've considered

In start.vaadin.com, I used to rely on [part="row"]:active to indicate the start of a drag, and apply a reduced opacity style in that case. But it only works because “long pressing" is not used for anything else in the Grid that displays the views you add to the app.

Screenshot 2023-02-10 at 16 06 46

Additional context

No response

@web-padawan web-padawan added enhancement New feature or request vaadin-grid labels Feb 10, 2023
@FrediWa FrediWa self-assigned this Jul 22, 2024
@tomivirkki
Copy link
Member

tomivirkki commented Jul 23, 2024

It would be convenient to have a built-in part name for this, but you can also generate one yourself:

let draggedItems = [];

grid.cellPartNameGenerator = (_, { item }) => {
  return draggedItems.includes(item) ? 'dragged-cell' : '';
};

grid.addEventListener('grid-dragstart', (e) => {
  draggedItems = e.detail.draggedItems;
  // Update the part names after a timeout to not have the styles applied for the ghost image
  setTimeout(() => grid.generateCellPartNames());
});

grid.addEventListener('grid-dragend', (e) => {
  draggedItems = [];
  grid.generateCellPartNames();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants