Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 757ce6d

Browse files
committed
fixes for carousel with pagination
1 parent ffab117 commit 757ce6d

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

packages/accessibility/src/behaviors/Carousel/carouselItemBehavior.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Accessibility } from '../../types'
2+
import * as keyboardKey from 'keyboard-key'
23

34
/**
45
* @specification
@@ -11,13 +12,17 @@ const carouselItemBehavior: Accessibility<CarouselItemProps> = props => ({
1112
root: {
1213
role: props.navigation ? 'tabpanel' : 'group',
1314
'aria-hidden': props.active ? 'false' : 'true',
14-
tabIndex: props.active ? 0 : -1,
15+
tabIndex: props.navigation ? props.active ? 0 : -1 : -1,
1516
},
1617
},
1718

1819
keyActions: {
19-
root: {},
20-
},
20+
root: {
21+
stopPropagation: {
22+
keyCombinations: [{ keyCode: keyboardKey.ArrowRight }, { keyCode: keyboardKey.ArrowLeft }]
23+
},
24+
},
25+
}
2126
})
2227

2328
export default carouselItemBehavior

packages/react/src/components/Carousel/Carousel.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,12 @@ class Carousel extends AutoControlledComponent<WithAsProp<CarouselProps>, Carous
184184
this.showPreviousSlide(e, true)
185185
},
186186
showNextSlideByPaddlePress: e => {
187-
e.preventDefault()
188-
const { activeIndex } = this.state
189-
const { circular, items, navigation } = this.props
190-
191-
this.showNextSlide(e, false)
192-
193-
// if 'next' paddle will disappear, will focus 'previous' one.
194-
if (!navigation && activeIndex >= items.length - 2 && !circular) {
195-
this.paddlePreviousRef.current.focus()
196-
}
187+
e.preventDefault()
188+
this.showNextSlide(e, false)
197189
},
198190
showPreviousSlideByPaddlePress: e => {
199191
e.preventDefault()
200-
const { activeIndex } = this.state
201-
const { circular, navigation } = this.props
202-
203192
this.showPreviousSlide(e, false)
204-
205-
// if 'previous' paddle will disappear, will focus 'next' one.
206-
if (!navigation && activeIndex <= 1 && !circular) {
207-
this.paddleNextRef.current.focus()
208-
}
209193
},
210194
}
211195

@@ -260,7 +244,8 @@ class Carousel extends AutoControlledComponent<WithAsProp<CarouselProps>, Carous
260244
<div style={styles.itemsContainerWrapper} {...accessibility.attributes.itemsContainerWrapper}>
261245
<div
262246
className={Carousel.slotClassNames.itemsContainer}
263-
aria-roledescription={ariaRoleDescription}
247+
aria-roledescription={ariaRoleDescription}
248+
aria-label="Portrait collection"
264249
style={styles.itemsContainer}
265250
{...accessibility.attributes.itemsContainer}
266251
{...applyAccessibilityKeyHandlers(
@@ -294,10 +279,18 @@ class Carousel extends AutoControlledComponent<WithAsProp<CarouselProps>, Carous
294279

295280
showPreviousSlide = (e: React.SyntheticEvent, focusItem: boolean) => {
296281
this.setActiveIndex(e, this.state.activeIndex - 1, focusItem)
282+
// if 'previous' paddle will disappear, will focus 'next' one.
283+
if (!this.props.navigation && this.state.activeIndex <= 1 && !this.props.circular) {
284+
this.paddleNextRef.current.focus()
285+
}
297286
}
298287

299288
showNextSlide = (e: React.SyntheticEvent, focusItem: boolean) => {
300289
this.setActiveIndex(e, this.state.activeIndex + 1, focusItem)
290+
// if 'next' paddle will disappear, will focus 'previous' one.
291+
if (!this.props.navigation && this.state.activeIndex >= this.props.items.length - 2 && !this.props.circular) {
292+
this.paddlePreviousRef.current.focus()
293+
}
301294
}
302295

303296
handlePaddleOverrides = (predefinedProps: ButtonProps, paddleName: string) => ({
@@ -390,6 +383,7 @@ class Carousel extends AutoControlledComponent<WithAsProp<CarouselProps>, Carous
390383
})
391384
) : (
392385
<Text
386+
aria-hidden="true"
393387
className={Carousel.slotClassNames.pagination}
394388
content={getItemPositionText(activeIndex, items.length)}
395389
/>

0 commit comments

Comments
 (0)