Skip to content

Commit

Permalink
Revert "Merge branch 'carousel-focus-fix'"
Browse files Browse the repository at this point in the history
This reverts commit d3523ab, reversing
changes made to 58ec236.
  • Loading branch information
IgnacioBecerra committed Feb 22, 2021
1 parent 6c91211 commit 7178c29
Showing 1 changed file with 1 addition and 37 deletions.
38 changes: 1 addition & 37 deletions packages/web-components/src/components/carousel/carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/setti
import ifNonNull from 'carbon-web-components/es/globals/directives/if-non-null.js';
import CaretLeft20 from 'carbon-web-components/es/icons/caret--left/20.js';
import CaretRight20 from 'carbon-web-components/es/icons/caret--right/20.js';
import HostListener from 'carbon-web-components/es/globals/decorators/host-listener';
import HostListenerMixin from 'carbon-web-components/es/globals/mixins/host-listener';
import DDSCard from '../card/card';
import styles from './carousel.scss';

const { prefix } = settings;
Expand All @@ -29,7 +26,7 @@ const { stablePrefix: ddsPrefix } = ddsSettings;
* @csspart next-button The button to go to the next page.
*/
@customElement(`${ddsPrefix}-carousel`)
class DDSCarousel extends HostListenerMixin(LitElement) {
class DDSCarousel extends LitElement {
/**
* The scrolling contents node.
*/
Expand Down Expand Up @@ -114,39 +111,6 @@ class DDSCarousel extends HostListenerMixin(LitElement) {
}
}

/**
* Handles card focus throughout pages.
*
* @param event The event.
*/
@HostListener('shadowRoot:focusin')
// @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 oldNotContains = target !== this && !this.contains(relatedTarget as DDSCard);
const currentCardIndex = Array.from(this.children).indexOf(target as HTMLElement);

// 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) {
// going forwards, change page depending on card index
if (currentCardIndex >= this.start + this.pageSize) {
const nextStart = currentCardIndex - (currentCardIndex % this.pageSize);
const pageOffset = this.start % this.pageSize;

this.start = nextStart + pageOffset;

// going backwards, change page depending on card index
} else if (currentCardIndex < this.start) {
this.start = Math.max(currentCardIndex + 1 - this.pageSize, 0);
}
}
};

/**
* Handles `click` event on the next button.
*/
Expand Down

0 comments on commit 7178c29

Please sign in to comment.