salesforce / salesforce/design-system-react
Carousel: Changing the number of items in the carousel crashes the component
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 982
- Forks
- 440
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at CarouselIndicators.render(), especially the loop over props.noOfIndicators and its access to props.items[index]. Reproduce the crash with the filtering example from the issue, then verify that changing the item count no longer causes a TypeError and that the carousel indicators remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100