Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carousel: Changing the number of items in the carousel crashes the component #2968

Open
sf-adam-randall opened this issue Oct 21, 2021 · 4 comments
Labels

Comments

@sf-adam-randall
Copy link

In CarouselIndicators.render() each panel index is looped through:

{[...Array(props.noOfIndicators).keys()].map((index) => {

later inside the loop, the code is trying to access props.items using that index, however that index is an index into the number of panels not items so this:

id = props.items[index].id;

causes a TypeError: Cannot read properties of undefined (reading 'id').

To duplicate:

  render() {
    let items = [
      {
        id: 0,
        heading: 'Zero',
      },
      {
        id: 1,
        heading: 'One'
      },
      {
        id: 2,
        heading: 'Two',
      },
      {
        id: 3,
        heading: 'Three'
      }
    ];
    if (this.state.filter) {
      items = [items[0]];
    }

    return (
      <div>
        <Button label="Toggle" onClick={() => this.setState({ filter: true }) } />
        <Carousel
            hasPreviousNextPanelNavigation
            items={items}
            itemsPerPanel={3}
        />
      </div>
    );
  }

When you click the button you will experience the error.

@welcome
Copy link

welcome bot commented Oct 21, 2021

Thanks for opening your first issue! 👋
If you have found this library helpful, please star it. A maintainer will try to respond within 7 days. If you haven’t heard anything by then, please bump this thread.

@sf-adam-randall
Copy link
Author

bump

@ashutosh887
Copy link

I would like to work on this Issue
Please assign to me and guide me once

@stale
Copy link

stale bot commented Apr 18, 2022

This issue has been automatically marked as stale, because it has not had recent activity. It will be closed if no further activity occurs. Maintainers are responsible for tech debt and project health. This is most likely a new components or component feature request. Please submit a pull request for or request feedback on this feature. Thank you.

@stale stale bot added the stale label Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants