Full height carousel
See original GitHub issueI had to create a carousel that takes 100% space both vertically and horizontally. Here’s the wrapper I came up with:
import React from 'react';
import { CarouselProvider } from 'pure-react-carousel';
import PropTypes from 'prop-types';
class FullContainerCarouselProvider extends React.Component {
static propTypes = {
children: PropTypes.node.isRequired
};
constructor() {
super();
this.nodeRef = React.createRef();
this.state = {
wrapperHeight: 0,
wrapperWidth: 0
};
this.updateDimensions = this.updateDimensions.bind(this);
}
updateDimensions() {
if (!this.nodeRef) return;
const node = this.nodeRef.current;
const outerNode = node.parentNode;
this.setState({
heightProportion: outerNode.clientHeight,
widthProportion: outerNode.clientWidth
});
}
componentDidMount() {
this.updateDimensions();
window.addEventListener('resize', this.updateDimensions);
}
componentWillUnmount() {
window.removeEventListener('resize', this.updateDimensions);
}
render() {
return (
<CarouselProvider
ref={this.nodeRef}
naturalSlideWidth={this.state.widthProportion}
naturalSlideHeight={this.state.heightProportion}
{...this.props}
>
{this.props.children}
</CarouselProvider>
);
}
}
export default FullContainerCarouselProvider;
The use case is so common (I guess) that it would be better to make naturalSlideWidth
/naturalSlideHeight
optional. If they are omitted, the carousel would occupy all the outer space available.
If we will make naturalSlideWidth
/naturalSlideHeight
optional, there is a catch that should be mentioned in the readme: the containing element must have its dimensions specified.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:15 (9 by maintainers)
Top Results From Across the Web
Adjust Bootstrap carousel to full height - Stack Overflow
How do I set the height of Carousel to Full, I want it to occupy the screen when the user opens the page...
Read more >Bootstrap 3 full height carousel - CodePen
<div class="carousel-caption">. 13. <h1>Bootstrap 3 full height carousel</h1>. 14. <p class="lead">With slide captions included.</p>.
Read more >Consistent Height Carousels with CSS Gradients and Object Fit
The position will be absolute so that it's relative to the parent component, I'm making the gradient start 0 pixels from the top...
Read more >Carousel - full height on mobile - Bootstrap Studio Forum
Carousel - full height on mobile · In the Overview Panel, select the Slide · Go to the Options panel, go to Flexbox...
Read more >Set Maximum Height for Carousel
Hi, How do i set min/max height for mdb-carousel and the images should fit into the desired height x width.
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 FreeTop 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
Top GitHub Comments
Hi I am useing your carousel in a phonegap Material UI SPA. The user can swipe thru a bunch of pages (lists, no images). I just want the carousel to fill its parent container, so naturalSlideHeight and naturalSlideWidth are no good to me. My SPA has a responsive sidebar menu depending on screen width. Hoping you can make this vanilla scenario practical
Heyo, I was trying to use this component, but the use of the naturalHeight naturalWidth props is very very confusing… also as stated in this issue, sometimes you just want a carousel that fills the entire screen so far I’ve been stumbling around the myriad of possible props I can pass to this component (intrinsicHeight?) and nothing seems to work
It seems like when created the focus was a very specific use case in mind and has been retro fitted to appeal to the broadest possible cases
anyways, I’m about to give up and try a different component, but maybe someone can point out to me if they actually managed to get this working as a full height component?