Scroll/Drag doesn't work until window is resized
See original GitHub issueBug 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 touseEmblaCarousel()
) before I do the resizing, the object is notnull
orundefined
. - 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
- Populate the carousel with enough items to merit scrolling
- Clicking the navigation buttons will not do anything.
- Dragging the carousel items to scroll will not do anything.
- Resize the window and then put it back to its original size.
- 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:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for confirming @ej-mitchell 👍. Enjoy!
It worked 😻 thank you! (I had a hunch that it was scenario
1
)