@@ -384,11 +384,60 @@ describe('useSliderThumb', () => {
384384 // Drag thumb
385385 let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
386386 fireEvent . keyDown ( thumb0 , { key : 'ArrowRight' } ) ;
387+ fireEvent . keyUp ( thumb0 , { key : 'ArrowRight' } ) ;
387388 expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 11 ] ) ;
388389 expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
389390 expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 11 ] ) ;
390391 expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 1 ) ;
391392 expect ( stateRef . current . values ) . toEqual ( [ 11 ] ) ;
393+
394+ fireEvent . keyDown ( thumb0 , { key : 'ArrowLeft' } ) ;
395+ fireEvent . keyUp ( thumb0 , { key : 'ArrowLeft' } ) ;
396+ expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 10 ] ) ;
397+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
398+ expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 10 ] ) ;
399+ expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 2 ) ;
400+ expect ( stateRef . current . values ) . toEqual ( [ 10 ] ) ;
401+ } ) ;
402+
403+ it ( 'can be moved with keys at the beginning of the slider' , ( ) => {
404+ let onChangeSpy = jest . fn ( ) ;
405+ let onChangeEndSpy = jest . fn ( ) ;
406+ render ( < Example onChange = { onChangeSpy } onChangeEnd = { onChangeEndSpy } aria-label = "Slider" defaultValue = { [ 0 ] } /> ) ;
407+
408+ let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
409+ fireEvent . keyDown ( thumb0 , { key : 'ArrowLeft' } ) ;
410+ fireEvent . keyUp ( thumb0 , { key : 'ArrowLeft' } ) ;
411+ expect ( onChangeSpy ) . not . toHaveBeenCalled ( ) ;
412+ expect ( onChangeEndSpy ) . toHaveBeenCalledWith ( [ 0 ] ) ;
413+
414+ fireEvent . keyDown ( thumb0 , { key : 'ArrowRight' } ) ;
415+ fireEvent . keyUp ( thumb0 , { key : 'ArrowRight' } ) ;
416+ expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 1 ] ) ;
417+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
418+ expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 1 ] ) ;
419+ expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 2 ) ;
420+ expect ( stateRef . current . values ) . toEqual ( [ 1 ] ) ;
421+ } ) ;
422+
423+ it ( 'can be moved with keys at the end of the slider' , ( ) => {
424+ let onChangeSpy = jest . fn ( ) ;
425+ let onChangeEndSpy = jest . fn ( ) ;
426+ render ( < Example onChange = { onChangeSpy } onChangeEnd = { onChangeEndSpy } aria-label = "Slider" defaultValue = { [ 100 ] } /> ) ;
427+
428+ let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
429+ fireEvent . keyDown ( thumb0 , { key : 'ArrowRight' } ) ;
430+ fireEvent . keyUp ( thumb0 , { key : 'ArrowRight' } ) ;
431+ expect ( onChangeSpy ) . not . toHaveBeenCalled ( ) ;
432+ expect ( onChangeEndSpy ) . toHaveBeenCalledWith ( [ 100 ] ) ;
433+
434+ fireEvent . keyDown ( thumb0 , { key : 'ArrowLeft' } ) ;
435+ fireEvent . keyUp ( thumb0 , { key : 'ArrowLeft' } ) ;
436+ expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 99 ] ) ;
437+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
438+ expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 99 ] ) ;
439+ expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 2 ) ;
440+ expect ( stateRef . current . values ) . toEqual ( [ 99 ] ) ;
392441 } ) ;
393442
394443 it ( 'can be moved with keys (vertical)' , ( ) => {
@@ -399,18 +448,64 @@ describe('useSliderThumb', () => {
399448 // Drag thumb
400449 let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
401450 fireEvent . keyDown ( thumb0 , { key : 'ArrowRight' } ) ;
451+ fireEvent . keyUp ( thumb0 , { key : 'ArrowRight' } ) ;
402452 expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 11 ] ) ;
403453 expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
404454 fireEvent . keyDown ( thumb0 , { key : 'ArrowUp' } ) ;
455+ fireEvent . keyUp ( thumb0 , { key : 'ArrowUp' } ) ;
405456 expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 12 ] ) ;
406457 expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
407458 fireEvent . keyDown ( thumb0 , { key : 'ArrowDown' } ) ;
459+ fireEvent . keyUp ( thumb0 , { key : 'ArrowDown' } ) ;
408460 expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 11 ] ) ;
409461 expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 3 ) ;
410462 fireEvent . keyDown ( thumb0 , { key : 'ArrowLeft' } ) ;
463+ fireEvent . keyUp ( thumb0 , { key : 'ArrowLeft' } ) ;
411464 expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 10 ] ) ;
412465 expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 4 ) ;
413466 } ) ;
467+
468+ it ( 'can be moved with keys (vertical) at the bottom of the slider' , ( ) => {
469+ let onChangeSpy = jest . fn ( ) ;
470+ let onChangeEndSpy = jest . fn ( ) ;
471+ render ( < Example onChange = { onChangeSpy } onChangeEnd = { onChangeEndSpy } aria-label = "Slider" defaultValue = { [ 0 ] } orientation = "vertical" /> ) ;
472+
473+ // Drag thumb
474+ let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
475+ fireEvent . keyDown ( thumb0 , { key : 'ArrowDown' } ) ;
476+ fireEvent . keyUp ( thumb0 , { key : 'ArrowDown' } ) ;
477+ expect ( onChangeSpy ) . not . toHaveBeenCalled ( ) ;
478+ expect ( onChangeEndSpy ) . toHaveBeenCalledWith ( [ 0 ] ) ;
479+
480+ fireEvent . keyDown ( thumb0 , { key : 'ArrowUp' } ) ;
481+ fireEvent . keyUp ( thumb0 , { key : 'ArrowUp' } ) ;
482+ expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 1 ] ) ;
483+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
484+ expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 1 ] ) ;
485+ expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 2 ) ;
486+ expect ( stateRef . current . values ) . toEqual ( [ 1 ] ) ;
487+ } ) ;
488+
489+ it ( 'can be moved with keys (vertical) at the top of the slider' , ( ) => {
490+ let onChangeSpy = jest . fn ( ) ;
491+ let onChangeEndSpy = jest . fn ( ) ;
492+ render ( < Example onChange = { onChangeSpy } onChangeEnd = { onChangeEndSpy } aria-label = "Slider" defaultValue = { [ 100 ] } orientation = "vertical" /> ) ;
493+
494+ // Drag thumb
495+ let thumb0 = screen . getByTestId ( 'thumb' ) . firstChild ;
496+ fireEvent . keyDown ( thumb0 , { key : 'ArrowUp' } ) ;
497+ fireEvent . keyUp ( thumb0 , { key : 'ArrowUp' } ) ;
498+ expect ( onChangeSpy ) . not . toHaveBeenCalled ( ) ;
499+ expect ( onChangeEndSpy ) . toHaveBeenCalledWith ( [ 100 ] ) ;
500+
501+ fireEvent . keyDown ( thumb0 , { key : 'ArrowDown' } ) ;
502+ fireEvent . keyUp ( thumb0 , { key : 'ArrowDown' } ) ;
503+ expect ( onChangeSpy ) . toHaveBeenLastCalledWith ( [ 99 ] ) ;
504+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
505+ expect ( onChangeEndSpy ) . toHaveBeenLastCalledWith ( [ 99 ] ) ;
506+ expect ( onChangeEndSpy ) . toHaveBeenCalledTimes ( 2 ) ;
507+ expect ( stateRef . current . values ) . toEqual ( [ 99 ] ) ;
508+ } ) ;
414509 } ) ;
415510 } ) ;
416511} ) ;
0 commit comments