From 56684ea0b2dd482c70fa2a574e4f069f0623d959 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 24 Jul 2024 15:54:35 -0700 Subject: [PATCH] fix(carousel): Prevent duplicate animation when navigating via keyboard --- .../src/components/carousel/carousel.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/calcite-components/src/components/carousel/carousel.tsx b/packages/calcite-components/src/components/carousel/carousel.tsx index fb15ae06c3b..3185becb26b 100644 --- a/packages/calcite-components/src/components/carousel/carousel.tsx +++ b/packages/calcite-components/src/components/carousel/carousel.tsx @@ -494,6 +494,8 @@ export class Carousel return; } + const lastItem = this.items.length - 1; + switch (event.key) { case " ": case "Enter": @@ -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; } };