From ccc6d465cc9848695b81e50b59b60e0dbc5b03c3 Mon Sep 17 00:00:00 2001 From: IgnacioBecerra Date: Tue, 2 Feb 2021 12:16:53 -0800 Subject: [PATCH] fix(carousel): considered focus cases --- .../web-components/src/components/carousel/carousel.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/web-components/src/components/carousel/carousel.ts b/packages/web-components/src/components/carousel/carousel.ts index 48517ed9433..3a1edf0e769 100644 --- a/packages/web-components/src/components/carousel/carousel.ts +++ b/packages/web-components/src/components/carousel/carousel.ts @@ -123,12 +123,13 @@ class DDSCarousel extends HostListenerMixin(LitElement) { // @ts-ignore: The decorator refers to this method but TS thinks this method is not referred to private _handleFocus = async ({ target, relatedTarget }: FocusEvent) => { const currentContains = target !== this && this.contains(target as DDSCard); - const oldContains = target !== this && !this.contains(relatedTarget as DDSCard); + const oldNotContains = target !== this && !this.contains(relatedTarget as DDSCard); const currentCardIndex = Array.from(this.children).indexOf(target as HTMLElement); - // reset to first page if tabbing back into the carousel after previously moving pages - if (currentContains && oldContains) { - this.start = 0; + // keep current page if tabbing back into the carousel after previously moving pages + if (currentContains && oldNotContains && currentCardIndex === 0) { + (this.children[this.start] as HTMLElement).focus(); + return; } if (currentContains) {