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

Sort items only onEnd #2394

Open
neo-noire opened this issue Jul 23, 2024 · 1 comment
Open

Sort items only onEnd #2394

neo-noire opened this issue Jul 23, 2024 · 1 comment

Comments

@neo-noire
Copy link

Hi, I'm looking for a way to block sorting animation during move event. So basically I'd like to item to change it place only when I drop item to it's new position. I want to replicate notion dnd behavior.
new

@JeffJassky
Copy link

JeffJassky commented Sep 10, 2024

Do something like this:

...
onStart(e: Sortable.SortableEvent) {
  const index = Math.max(e.oldIndex as number, 0)
  const clone = e.from.insertBefore(
	  e.item.cloneNode(true),
	  e.from.children[index]
  ) as HTMLElement
  clone.classList.add('sortable-placeholder')
  clone.classList.remove('sortable-chosen', 'sortable-ghost')
}
...

That will leave a persistent clone in-place whole you drag the selected item around.

Then you just need to style the ghost to turn it into a blue line.

// basically make the sortable ghost completely hidden
.sortable-ghost {
	display: block;
	width: 100%;
	text-indent: -9999px;
	font-size: 0.001px;
	line-height: 0;
	color: transparent;
	border: none;
}

// ensure all content inside of it is hidden
.sortable-ghost * {
	display: none; 
}

// your actual blue line
.sortable-ghost:before {
content: '';
position: absolute;
top: -1.5px;
right: 0;
left: 0;
height: 3px;
background: blue;
border-radius: 3px;
animation: fade 250ms ease-in-out forwards;
}

That's it.

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

No branches or pull requests

2 participants