Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(carousel): improved tab page navigation #5035

Merged
Merged
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
caea15c
fix(megamenu): fixed uncentered arrow icon in safari
IgnacioBecerra Nov 24, 2020
e0827fd
Revert "fix(megamenu): fixed uncentered arrow icon in safari"
IgnacioBecerra Nov 24, 2020
d7c4f8b
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 24, 2020
370161c
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 25, 2020
7ac3c4e
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 30, 2020
b3bf936
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 1, 2020
a9d195d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 3, 2020
d62d6d4
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 7, 2020
5392a08
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 7, 2020
90a961a
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 8, 2020
41fbdd5
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 9, 2020
95f4af5
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 10, 2020
a9a4511
Merge branch 'master' of https://github.com/IgnacioBecerra/ibm-dotcom…
IgnacioBecerra Dec 15, 2020
671764b
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 16, 2020
e52de62
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 11, 2021
23c0161
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 12, 2021
81132f4
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 15, 2021
227309d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 19, 2021
910a43c
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 20, 2021
1142e4d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Jan 27, 2021
00f46f5
fix(carousel): improved tab page navigation
IgnacioBecerra Jan 28, 2021
c06974e
fix(carousel): consolidated logic
IgnacioBecerra Jan 29, 2021
ad92d2f
fix(carousel): updated page calculation
IgnacioBecerra Jan 30, 2021
889721a
fix(footer): updated index calculations
IgnacioBecerra Feb 1, 2021
baf1f3a
fix(carousel): considered focus cases
IgnacioBecerra Feb 2, 2021
6a8689f
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Feb 4, 2021
3a93494
Merge branch 'master' into carousel-focus-fix
asudoh Feb 4, 2021
cacd606
fix(carousel): considered offset page start
IgnacioBecerra Feb 4, 2021
8abb24c
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Feb 4, 2021
58ec236
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Feb 8, 2021
7196136
Merge branch 'carousel-focus-fix' of https://github.com/IgnacioBecerr…
IgnacioBecerra Feb 8, 2021
3db21ec
fix(carousel): consolidated start logic even further
IgnacioBecerra Feb 9, 2021
b4cdb5a
fix(carousel): stop default scroll upon focus
IgnacioBecerra Feb 10, 2021
aea7029
fix(carousel): focus on last card when tabbing back from the bottom
IgnacioBecerra Feb 10, 2021
ef25a3a
fix(carousel): using lit-html template for event listener
IgnacioBecerra Feb 10, 2021
5db8fe7
fix(carousel): added comment explaining logic
IgnacioBecerra Feb 11, 2021
8ca1216
Merge branch 'master' into carousel-focus-fix
IgnacioBecerra Feb 12, 2021
1b9e779
Merge branch 'master' into carousel-focus-fix
kodiakhq[bot] Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/web-components/src/components/carousel/carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ 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 @@ -26,7 +29,7 @@ const { stablePrefix: ddsPrefix } = ddsSettings;
* @csspart next-button The button to go to the next page.
*/
@customElement(`${ddsPrefix}-carousel`)
class DDSCarousel extends LitElement {
class DDSCarousel extends HostListenerMixin(LitElement) {
/**
* The scrolling contents node.
*/
Expand Down Expand Up @@ -111,6 +114,34 @@ class DDSCarousel extends 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 }: FocusEvent) => {
const currentContains = target !== this && this.contains(target 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 && currentCardIndex === 0) {
this.start = 0;
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved
}

if (currentContains) {
// going forwards, change page depending on card index
if (currentCardIndex >= this.start + this.pageSize) {
this.start = Math.min(currentCardIndex, this._total + 1 - this.pageSize);
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

// going backwards, change page depending on card index
} else if (currentCardIndex < this.start) {
this.start = currentCardIndex + 1 - this.pageSize;
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved
}
}
};

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