File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ describe('Carousel', () => {
20
20
afterEach ( ( ) => XunloadFixtures ( ) ) ;
21
21
22
22
describe ( 'carousel plugin' , ( ) => {
23
+ afterEach ( ( ) => {
24
+ M . Carousel . getInstance ( document . querySelector ( '.carousel' ) ) . destroy ( ) ;
25
+ } ) ;
26
+
23
27
it ( 'No wrap next and prev should not overflow' , ( done ) => {
24
28
const noWrap = M . Carousel . init ( document . querySelector ( '#slider-no-wrap' ) , {
25
29
duration : 10 ,
@@ -39,5 +43,19 @@ describe('Carousel', () => {
39
43
} , 30 ) ;
40
44
} , 50 ) ;
41
45
} ) ;
46
+
47
+ it ( 'should change index and focus its respective item on indicator click' , ( done ) => {
48
+ const carousel = M . Carousel . init ( document . querySelector ( '.carousel' ) , {
49
+ duration : 10 ,
50
+ indicators : true
51
+ } ) ;
52
+
53
+ document . querySelectorAll ( '.indicator-item' ) [ 1 ] . click ( ) ;
54
+ setTimeout ( ( ) => {
55
+ expect ( carousel . center ) . toEqual ( 1 , 'carousel item was not visible after indicator interaction' ) ;
56
+ done ( ) ;
57
+ } , 30 ) ;
58
+ } ) ;
59
+
42
60
} ) ;
43
61
} ) ;
Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ export class Carousel extends Component<CarouselOptions> {
133
133
if ( this . showIndicators ) {
134
134
const indicator = document . createElement ( 'li' ) ;
135
135
indicator . classList . add ( 'indicator-item' ) ;
136
+ indicator . tabIndex = 0 ;
136
137
if ( i === 0 ) {
137
138
indicator . classList . add ( 'active' ) ;
138
139
}
@@ -211,6 +212,7 @@ export class Carousel extends Component<CarouselOptions> {
211
212
if ( this . showIndicators && this . _indicators ) {
212
213
this . _indicators . querySelectorAll ( '.indicator-item' ) . forEach ( ( el ) => {
213
214
el . addEventListener ( 'click' , this . _handleIndicatorClick ) ;
215
+ el . addEventListener ( 'keypress' , this . _handleIndicatorKeyPress ) ;
214
216
} ) ;
215
217
}
216
218
// Resize
@@ -352,6 +354,17 @@ export class Carousel extends Component<CarouselOptions> {
352
354
353
355
_handleIndicatorClick = ( e : Event ) => {
354
356
e . stopPropagation ( ) ;
357
+ this . _handleIndicatorInteraction ( e ) ;
358
+ }
359
+
360
+ _handleIndicatorKeyPress = ( e : KeyboardEvent ) => {
361
+ e . stopPropagation ( ) ;
362
+ if ( Utils . keys . ENTER . includes ( e . key ) ) {
363
+ this . _handleIndicatorInteraction ( e ) ;
364
+ }
365
+ }
366
+
367
+ _handleIndicatorInteraction = ( e : Event ) => {
355
368
const indicator = ( < HTMLElement > e . target ) . closest ( '.indicator-item' ) ;
356
369
if ( indicator ) {
357
370
const index = [ ...indicator . parentNode . children ] . indexOf ( indicator ) ;
You can’t perform that action at this time.
0 commit comments