Skip to content

swiper.isEnd returns true, disabling the navigation buttons on first load even when slides are available to scroll #7969

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

Open
5 of 6 tasks
talalmedudy opened this issue Apr 23, 2025 · 1 comment
Labels

Comments

@talalmedudy
Copy link

Check that this is really a bug

  • I confirm

Reproduction link

Unable to reproduce as the issue is from a private repository.

Bug description

When swiper is loaded, isEnd is returned to be as true, which disables swiper's next slide button, even though slides are available and can be scrolled using mouse drag. Using mouse drag then updates the swiper, which then in turn enables the forward navigation button. This only happens when on certain screen dimensions and swiper width, as this issue disappears when i change my browser screen width.

Expected Behavior

Swiper should wait until all the slides have been loaded to calculate the correct width for the slides to determine whether the last slide has been reached.

Actual Behavior

Swiper returns isEnd prematurely before the swiper has fully loaded, giving the wrong value and hence disabling the forward navigation button.

Swiper version

11.2.6

Platform/Target and Browser Versions

Firefox 137.0.2, Safari 18.3

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
@talalmedudy
Copy link
Author

talalmedudy commented Apr 23, 2025

For anyone facing a similar issue, i've developed a small workaround, where I set a timeout inside a useEffect for my custom hook which is responsible for initializing and returning the swiper helper functions:

  const handleOnToFromEdge = useCallback(() => {
    setFirstSlide(swiper?.isBeginning)
    setLastSlide(swiper?.isEnd)
  }, [swiper])

  useEffect(() => {
    if (!swiper) return

    // timeout to refresh swiper after it loads to recalculate isEnd
    setTimeout(() => {
      handleOnToFromEdge()
    }, 100)

    handleOnToFromEdge()
  }, [swiper?.isBeginning, swiper?.isEnd, handleOnToFromEdge])

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

No branches or pull requests

1 participant