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.

Keen slider doesn't work if I place it on a modal?

See original GitHub issue

Hello, I am creating a next js application. I use keen slider in my several project. First of all Thanks to the all developer of keen slider. It is a amazing slider. But I am facing one problem when I place keen slider into a modal in my current project. Can you help me or is it an a serious issue?

Here is the modal component–

const Modals = ({ details, btnText, works, name, icon }) => {
    const [visible, setVisible] = useState(false);
    const modalToggler = () => {
        setVisible(!visible)
    }
    return (
        <Box>
            <ButtonBase onClick={modalToggler} >
                Open Modal
            </ButtonBase>
            <Rodal
                visible={visible}
                onClose={modalToggler}
            >
                <Typography variant="h5" component="h5">
                    {name}
                </Typography>
                // Carousel components
                <Carousels works={works} visible={visible} />
            </Rodal>
        </Box>
    );
};
export default Modals;

And this is the carousel component–

import { useState } from "react";
import { useKeenSlider } from "keen-slider/react";
import "keen-slider/keen-slider.min.css";

const Carousels = ({ works, visible }) => {
    const [currentSlide, setCurrentSlide] = useState(0)
    const [loaded, setLoaded] = useState(false)
    const [sliderRef, instanceRef] = useKeenSlider({
        initial: 0,
        slideChanged(slider) {
            setCurrentSlide(slider.track.details.rel)
        },
        created() {
            setLoaded(true)
        },
    })
    return (
        <div ref={sliderRef} className="keen-slider"> // Here I try it also `ref={visible ? sliderRef: null}` But not working
            {works &&
                works.map((work, i) => (
                    <div key={i} className="keen-slider__slide number-slide1">
                        <img src={work.image} />
                    </div>
                ))
            }
        </div>
    );
};
export default Carousels;

It just show a white screen. Not showing any carousel. But when I place it outside the modal then it works perfectly. What is the problem when I place it into modal.

Again thanks.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
siamahnaf198commented, Dec 8, 2021

This is like amazing. Thank you very much @rcbyr .

Love from Bangladesh. A team of web development Code Station 21

1reaction
rcbyrcommented, Dec 4, 2021

You could do something like that (the version is 6.3.0) https://codesandbox.io/s/modest-wood-mkdsl?file=/Components/carousel.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular / Keen-Slider: Slider just work in modal when ...
Your problem is as suspected. The keen-slider tries to grab the width of the parent container before angular has finished updating the content ......
Read more >
Carousel doesn't seem to behave if placed within a modal ...
Your issue is likely that the carousel is hidden when initialized and dimensions are not properly calculated. If you are on 1.4, you...
Read more >
Documentation
It is possible that the render performance of the browser slows down, if you have slides with some complexity in markup and CSS....
Read more >
Modal - Metronic - Keenthemes
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it. Launch...
Read more >
keen-slider doesn't trigger : r/reactjs
keen -slider doesn't trigger ... For anyone who encountered this problem, I ended up doing a workaround for the options object. It's the...
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