From 757ce6dcfc3b452db7a793f9a53aec10da0f6ec4 Mon Sep 17 00:00:00 2001 From: Milan Turon Date: Mon, 27 Jan 2020 16:23:09 +0100 Subject: [PATCH 01/17] fixes for carousel with pagination --- .../Carousel/carouselItemBehavior.ts | 11 +++++-- .../src/components/Carousel/Carousel.tsx | 32 ++++++++----------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/accessibility/src/behaviors/Carousel/carouselItemBehavior.ts b/packages/accessibility/src/behaviors/Carousel/carouselItemBehavior.ts index c848de36c2..fdf470dfd8 100644 --- a/packages/accessibility/src/behaviors/Carousel/carouselItemBehavior.ts +++ b/packages/accessibility/src/behaviors/Carousel/carouselItemBehavior.ts @@ -1,4 +1,5 @@ import { Accessibility } from '../../types' +import * as keyboardKey from 'keyboard-key' /** * @specification @@ -11,13 +12,17 @@ const carouselItemBehavior: Accessibility = props => ({ root: { role: props.navigation ? 'tabpanel' : 'group', 'aria-hidden': props.active ? 'false' : 'true', - tabIndex: props.active ? 0 : -1, + tabIndex: props.navigation ? props.active ? 0 : -1 : -1, }, }, keyActions: { - root: {}, - }, + root: { + stopPropagation: { + keyCombinations: [{ keyCode: keyboardKey.ArrowRight }, { keyCode: keyboardKey.ArrowLeft }] + }, + }, + } }) export default carouselItemBehavior diff --git a/packages/react/src/components/Carousel/Carousel.tsx b/packages/react/src/components/Carousel/Carousel.tsx index e1838f85dd..87b2cde70b 100644 --- a/packages/react/src/components/Carousel/Carousel.tsx +++ b/packages/react/src/components/Carousel/Carousel.tsx @@ -184,28 +184,12 @@ class Carousel extends AutoControlledComponent, Carous this.showPreviousSlide(e, true) }, showNextSlideByPaddlePress: e => { - e.preventDefault() - const { activeIndex } = this.state - const { circular, items, navigation } = this.props - - this.showNextSlide(e, false) - - // if 'next' paddle will disappear, will focus 'previous' one. - if (!navigation && activeIndex >= items.length - 2 && !circular) { - this.paddlePreviousRef.current.focus() - } + e.preventDefault() + this.showNextSlide(e, false) }, showPreviousSlideByPaddlePress: e => { e.preventDefault() - const { activeIndex } = this.state - const { circular, navigation } = this.props - this.showPreviousSlide(e, false) - - // if 'previous' paddle will disappear, will focus 'next' one. - if (!navigation && activeIndex <= 1 && !circular) { - this.paddleNextRef.current.focus() - } }, } @@ -260,7 +244,8 @@ class Carousel extends AutoControlledComponent, Carous
, Carous showPreviousSlide = (e: React.SyntheticEvent, focusItem: boolean) => { this.setActiveIndex(e, this.state.activeIndex - 1, focusItem) + // if 'previous' paddle will disappear, will focus 'next' one. + if (!this.props.navigation && this.state.activeIndex <= 1 && !this.props.circular) { + this.paddleNextRef.current.focus() + } } showNextSlide = (e: React.SyntheticEvent, focusItem: boolean) => { this.setActiveIndex(e, this.state.activeIndex + 1, focusItem) + // if 'next' paddle will disappear, will focus 'previous' one. + if (!this.props.navigation && this.state.activeIndex >= this.props.items.length - 2 && !this.props.circular) { + this.paddlePreviousRef.current.focus() + } } handlePaddleOverrides = (predefinedProps: ButtonProps, paddleName: string) => ({ @@ -390,6 +383,7 @@ class Carousel extends AutoControlledComponent, Carous }) ) : (