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

Add keep css class option #854

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

heyyo-droid
Copy link

Allow to keep some css class from dragged element and apply them to placehoder.

Copy link
Owner

@lukasoppermann lukasoppermann left a comment

Choose a reason for hiding this comment

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

Please remove all files in the dist folder from the pr. This is always done on release only.

@@ -482,6 +482,10 @@ export default function sortable (sortableElements, options: configuration|objec
dragging.style.display = dragging.oldDisplay
delete dragging.oldDisplay
}
// We need to reset placeholder if any css class were added.
options.keepCssClass.forEach(className => {
store(sortableElement).placeholder.classList.remove(className)
Copy link
Owner

Choose a reason for hiding this comment

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

This can be done in one step https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove sot that all classes are provided at once.

I think this should work: remove(...options.keepCssClass)

Copy link
Author

Choose a reason for hiding this comment

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

Nice, I will change that.

@@ -552,6 +556,13 @@ export default function sortable (sortableElements, options: configuration|objec
store(sortableElement).placeholder.style.height = draggingHeight + 'px'
store(sortableElement).placeholder.style.width = draggingWidth + 'px'
}
// Keep some CSS class fo the dragged element, to keep style.
Copy link
Owner

Choose a reason for hiding this comment

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

fo = for in comment

@@ -552,6 +556,13 @@ export default function sortable (sortableElements, options: configuration|objec
store(sortableElement).placeholder.style.height = draggingHeight + 'px'
store(sortableElement).placeholder.style.width = draggingWidth + 'px'
}
// Keep some CSS class fo the dragged element, to keep style.
// Usefull if sortable elements have different dimensions according class.
options.keepCssClass.forEach(className => {
Copy link
Owner

Choose a reason for hiding this comment

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

I think from a performance point of view you should first get the elements you want to add. Maybe use filter to get the elements that are in both arrays.

Afterwards just like with remove, you can add all at once. DOM interactions are often expensive.
add(...comparedArray)

Copy link
Author

Choose a reason for hiding this comment

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

Sorry you lost me in the first sentence.
Second sentence nice did't know that too.

@@ -1,7 +1,8 @@
interface configuration {
items?: string,
handle?: string,
forcePlaceholderSize?:boolean;
forcePlaceholderSize?: boolean,
keepCssClass?: Array<string>,
Copy link
Owner

Choose a reason for hiding this comment

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

Let's rename this to keepClassesForPlaceholder.

@lukasoppermann
Copy link
Owner

Hey @heyyo-droid thank you for the PR. I left a few comments.

I am thinking if it may make more sense to have an initialize placeholder function that the user can define.
This would enable this use case but allow for more flexibility.

We would add a initPlaceholder: fn option. This would get the element it is a placeholder for and a clone of the placeholder and would return the placeholder element which in turn would be attached to the dom and moved into position.

What do you think?

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

Successfully merging this pull request may close these issues.

None yet

2 participants