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.

Full height carousel

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
petercuttingcommented, Mar 18, 2019

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

2reactions
ospfrancocommented, Dec 15, 2020

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?

Read more comments on GitHub >

github_iconTop 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 >

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