Skip to content

Commit

Permalink
fix(carousel): considered focus cases
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioBecerra committed Feb 22, 2021
1 parent 13781bf commit ccc6d46
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/web-components/src/components/carousel/carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ccc6d46

Please sign in to comment.