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

[Feature Request] Disable swapping if only 1 item exist #68

Closed
Crinchy opened this issue Sep 23, 2024 · 6 comments
Closed

[Feature Request] Disable swapping if only 1 item exist #68

Crinchy opened this issue Sep 23, 2024 · 6 comments

Comments

@Crinchy
Copy link

Crinchy commented Sep 23, 2024

Hey 👋

Currently you can swap even only 1 item exist, which makes absolutely no sense for me and it would be ugly to wrap the swapy init into an if statement. So i would disable the swap if only 1 item exists in the container.

I hope you see it the same way as I do. ❤️

@Crinchy Crinchy changed the title [Feature Request] Disable swapping if only 1 item exists [Feature Request] Disable swapping if only 1 item exist Sep 23, 2024
@TahaSh
Copy link
Owner

TahaSh commented Sep 26, 2024

Hey @Crinchy! I might be wrong, but I think keeping it draggable would be the more expected behavior, especially in cases where you can add slots dynamically. It would indicate that the items in the section have a dragging feature. If you want to disable it when there’s one item, you can call swapy.enable(false) for that condition.

However, if most people prefer disabling it, I’m totally okay with that too! Thanks for the suggestion!

@Crinchy
Copy link
Author

Crinchy commented Sep 26, 2024

Okay @TahaSh makes sense for me.

But swapy.enable(false); is not working correctly on my side, i still can swap element if i disable it for test.

This is the React Component in my next.js project:

export default function TagListComponent({ tags }: { tags: PortfolioTagType[] }) {
  useEffect(() => {
    const container = document.querySelector('.container')!;

    const swapy = createSwapy(container, {
      animation: 'dynamic',
      continuousMode: true,
      swapMode: 'drop'
    });

    swapy.enable(false);

    swapy.onSwapEnd(async ({ data }) => {
      console.log(data);
    });

    return () => {
      swapy.destroy();
    };
  }, [tags]);

  return (
    <div className='container grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-3'>
      {tags.map((tag) => (
        <div key={tag.uuid} data-swapy-slot={tag.uuid}>
          <div data-swapy-item={tag.uuid}>
            <TagEditDialog {...tag} />
          </div>
        </div>
      ))}
    </div>
  );
}

@TahaSh
Copy link
Owner

TahaSh commented Sep 26, 2024

@Crinchy I found the issue. It was related to react's strict mode. I'll fix it soon, thanks!

@Crinchy
Copy link
Author

Crinchy commented Sep 29, 2024

Hey @TahaSh 👋,

any eta on this?

Thanks buddy

@TahaSh
Copy link
Owner

TahaSh commented Sep 30, 2024

@Crinchy It should be fixed now :) (update to v0.4.0)

@Crinchy
Copy link
Author

Crinchy commented Sep 30, 2024

Thanks @TahaSh, yeah i can confirm it, its fixed ❤️

@Crinchy Crinchy closed this as completed Sep 30, 2024
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