question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll/Drag doesn't work until window is resized

See original GitHub issue

Bug is related to

  • The Vanilla JavaScript version
  • The React version
  • Documentation website
  • Other

Embla Carousel version

  • v4.2.0

Describe the bug

  • When I first populate the carousel with several items, I am unable to use the navigation arrows or to drag through my items.
  • When I resize the window to a different size (either larger or smaller), then restore it to its original size, then the arrows and drag functionality works.
  • When I log embla (which is set to useEmblaCarousel()) before I do the resizing, the object is not null or undefined.
  • I’m still trying to determine whether there are parent styles (in overarching components) causing this issue, but I can’t see anything in these components that would cause the dragging and scrollNext/scrollPrev methods to not work.

CodeSandbox

  • Unfortunately, I’m working for a client and am unable to share the full code. However, I scrubbed the important variable names and have the carousel code below. (I’m using styled components.)
const OverflowContainer = styled.div`
    overflow: hidden;
    height: 100%;
    min-width: 80%;
`;

const FlexContainer = styled.div`
    display: flex;
    height: 100%;
    width: 80%;
`;

const Slide = styled.div`
    position: relative;
    flex: 0 0 15%;
    height: 80%;
`;

const PreviousButton = styled.button`
    cursor: pointer;
    background-color: green;
    width: 30px;
    height: 30px;
`;

const NextButton = styled.button`
    cursor: pointer;
    background-color: blue;
    width: 30px;
    height: 30px;
`;

interface Props {
    slides: JSX.Element[];
}

const ExampleCarousel = ({mergedVideos}: Props) => {
    const [carouselRef, embla] = useEmblaCarousel();

    const scrollPrev = useCallback(() => {
        embla && embla.scrollPrev(); // embla evaluates properly here - failure happens in scrollPrev()?
    }, [embla]);
    const scrollNext = useCallback(() => {
        embla && embla.scrollNext(); // embla evaluates properly here - failure happens in scrollNext()?
    }, [embla]);

    const slideVideos = slides.map((m) => <Slide key={m.key}>{m}</Slide>);

    return (
        <>
            <OverflowContainer ref={carouselRef}>
                <FlexContainer>{slideVideos}</FlexContainer>
            </OverflowContainer>
            <PreviousButton onClick={scrollPrev} />
            <NextButton onClick={scrollNext} />
        </>
    );
};

export default ExampleCarousel;

Steps to reproduce

  1. Populate the carousel with enough items to merit scrolling
  2. Clicking the navigation buttons will not do anything.
  3. Dragging the carousel items to scroll will not do anything.
  4. Resize the window and then put it back to its original size.
  5. You should be able to use the navigation buttons and drag to scroll.

Expected behavior

  • I expect the scrolling behaviors to work immediately, and not after resizing my window.

Thank you! Let me know if there’s anything else I can provide… If this weren’t a client project, I would have gifs and other accompanying pieces for you. 😦 Apart from this strange issue, I’ve loved using Embla so far!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
davidjerlekecommented, Mar 23, 2021

Thanks for confirming @ej-mitchell 👍. Enjoy!

3reactions
ej-mitchellcommented, Mar 23, 2021

It worked 😻 thank you! (I had a hunch that it was scenario 1)

Read more comments on GitHub >

github_iconTop Results From Across the Web

scrollbar-hidden doesn't work when you resize the browser ...
Set 'scrollbar-hidden' to true with a window size that accommodates all the drag-scroll-items. Then resize the window and you will see the ...
Read more >
TextCtrl scrollbar unusable until window is resized
The issue that I'm running into is this: when I open a text file (the only functionality built in at this point) that's...
Read more >
ScrollTrigger only works when resizing window - GSAP
Hey everyone,. I am doing my first steps with GSAP right now. I am using it with Kirby and try to trigger some...
Read more >
Scrolling at edge of screen (Stop resize) - MacRumors Forums
All work the same way. move cursor toward right edge of window, until the "Resize" arrow appears. The window will scroll at that...
Read more >
I can not get the screen to re-size, so that I can drag it over, or ...
First, is your Firefox window maximized so you are working with the full width of the screen? On Windows, you typically can switch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found