Skip to content

Commit

Permalink
fix(carousel): Prevent duplicate animation when navigating via keyboa…
Browse files Browse the repository at this point in the history
…rd (#9848)

**Related Issue:** #9471

## Summary
When using `home` and `end` while focused on the Container, prevent
"re-navigating" to the currently active Carousel Item and showing a
duplicate animation. This matches the behavior when a user selects an
individual Carousel Item "dot", both with mouse or via keyboard.
  • Loading branch information
macandcheese authored and github-actions[bot] committed Jul 30, 2024
1 parent 0824f5d commit cfdbd44
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ export class Carousel
return;
}

const lastItem = this.items.length - 1;

switch (event.key) {
case " ":
case "Enter":
Expand All @@ -512,13 +514,19 @@ export class Carousel
break;
case "Home":
event.preventDefault();
if (this.selectedIndex === 0) {
return;
}
this.direction = "backward";
this.setSelectedItem(0, true);
break;
case "End":
event.preventDefault();
if (this.selectedIndex === lastItem) {
return;
}
this.direction = "forward";
this.setSelectedItem(this.items.length - 1, true);
this.setSelectedItem(lastItem, true);
break;
}
};
Expand Down

0 comments on commit cfdbd44

Please sign in to comment.