Keen slider doesn't work if I place it on a modal?
See original GitHub issueHello, 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:
- Created 2 years ago
- Comments:24 (5 by maintainers)
Top 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 >
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
This is like amazing. Thank you very much @rcbyr .
Love from Bangladesh. A team of web development Code Station 21
You could do something like that (the version is 6.3.0) https://codesandbox.io/s/modest-wood-mkdsl?file=/Components/carousel.js