From 62aa1e764a8f8422ef8d97ba8d24b2f2ec9840ce Mon Sep 17 00:00:00 2001 From: planctus Date: Mon, 27 Feb 2023 12:01:29 +0200 Subject: [PATCH 1/2] feat(focus): Handling keyboard on play button - FRONT-3870 --- .../vanilla/components/carousel/carousel.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/implementations/vanilla/components/carousel/carousel.js b/src/implementations/vanilla/components/carousel/carousel.js index bc7a38a732a..0b67dfa967b 100644 --- a/src/implementations/vanilla/components/carousel/carousel.js +++ b/src/implementations/vanilla/components/carousel/carousel.js @@ -80,6 +80,7 @@ export class Carousel { this.index = 1; this.total = 0; this.allowShift = true; + this.activeNav = null; this.autoPlay = null; this.autoPlayInterval = null; this.hoverAutoPlay = null; @@ -107,6 +108,7 @@ export class Carousel { this.dragEnd = this.dragEnd.bind(this); this.dragAction = this.dragAction.bind(this); this.handleFocus = this.handleFocus.bind(this); + this.handleKeyboardOnPlay = this.handleKeyboardOnPlay.bind(this); } /** @@ -180,6 +182,9 @@ export class Carousel { this.btnPlay.addEventListener('click', this.handleAutoPlay); this.btnPause.addEventListener('click', this.handleAutoPlay); } + if (this.btnPlay) { + this.btnPlay.addEventListener('keydown', this.handleKeyboardOnPlay); + } if (this.attachClickListener && this.btnNext) { this.btnNext.addEventListener( 'click', @@ -192,6 +197,7 @@ export class Carousel { this.shiftSlide.bind(this, 'prev', true) ); } + if (this.slidesContainer) { // Mouse events this.slidesContainer.addEventListener('mouseover', this.handleMouseOver); @@ -494,6 +500,26 @@ export class Carousel { } } + /** + * @param {Event} e + */ + handleKeyboardOnPlay(e) { + switch (e.key) { + case 'Tab': + case 'ArrowRight': + e.preventDefault(); + this.activeNav = queryOne( + '.ecl-carousel__navigation-item[aria-current="true"]' + ); + if (this.activeNav) { + this.activeNav.focus(); + } + break; + + default: + } + } + /** * Trigger events on focus. * @param {Event} e From ddd005fd3985f334bdc4e8494821a140bffd4a50 Mon Sep 17 00:00:00 2001 From: planctus Date: Wed, 1 Mar 2023 10:21:45 +0200 Subject: [PATCH 2/2] chore: improving keyboard nav in carousel, aligning styles in EU radio to the EC version - FRONT-3870 --- .../radio/__snapshots__/radio.test.js.snap | 5 --- .../vanilla/components/carousel/carousel.js | 41 ++++++++++++++++++- .../vanilla/components/radio/radio-eu.scss | 6 +-- .../components/radio/demo/data--default.js | 1 - 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/implementations/twig/components/radio/__snapshots__/radio.test.js.snap b/src/implementations/twig/components/radio/__snapshots__/radio.test.js.snap index 0c52b5a207f..03ab95f743b 100644 --- a/src/implementations/twig/components/radio/__snapshots__/radio.test.js.snap +++ b/src/implementations/twig/components/radio/__snapshots__/radio.test.js.snap @@ -211,7 +211,6 @@ exports[`Radio Default renders correctly 1`] = ` >