@@ -14,6 +14,7 @@ import {AriaColorSliderProps} from '@react-types/color';
14
14
import { ColorSliderState } from '@react-stately/color' ;
15
15
import { HTMLAttributes , RefObject } from 'react' ;
16
16
import { mergeProps } from '@react-aria/utils' ;
17
+ import { useKeyboard } from '@react-aria/interactions' ;
17
18
import { useLocale } from '@react-aria/i18n' ;
18
19
import { useSlider , useSliderThumb } from '@react-aria/slider' ;
19
20
@@ -61,6 +62,32 @@ export function useColorSlider(props: ColorSliderAriaOptions, state: ColorSlider
61
62
inputRef
62
63
} , state ) ;
63
64
65
+ let { step, pageSize} = state . value . getChannelRange ( channel ) ;
66
+ let { keyboardProps} = useKeyboard ( {
67
+ onKeyDown ( e ) {
68
+ // these are the cases that useMove or useSlider don't handle
69
+ if ( ! / ^ ( P a g e U p | P a g e D o w n ) $ / . test ( e . key ) ) {
70
+ e . continuePropagation ( ) ;
71
+ return ;
72
+ }
73
+ // same handling as useMove, stopPropagation to prevent useSlider from handling the event as well.
74
+ e . preventDefault ( ) ;
75
+ let pageStep = Math . max ( pageSize , step ) ;
76
+ // remember to set this so that onChangeEnd is fired
77
+ state . setThumbDragging ( 0 , true ) ;
78
+ switch ( e . key ) {
79
+ case 'PageUp' :
80
+ state . incrementThumb ( 0 , pageStep ) ;
81
+ break ;
82
+ case 'PageDown' :
83
+ state . decrementThumb ( 0 , pageStep ) ;
84
+ break ;
85
+ }
86
+ // wait a frame to ensure value has changed then unset this so that onChangeEnd is fired
87
+ state . setThumbDragging ( 0 , false ) ;
88
+ }
89
+ } ) ;
90
+
64
91
let generateBackground = ( ) => {
65
92
let value = state . getDisplayColor ( ) ;
66
93
let to : string ;
@@ -113,7 +140,7 @@ export function useColorSlider(props: ColorSliderAriaOptions, state: ColorSlider
113
140
background : generateBackground ( )
114
141
}
115
142
} ,
116
- inputProps,
143
+ inputProps : mergeProps ( inputProps , keyboardProps ) ,
117
144
thumbProps : {
118
145
...thumbProps ,
119
146
style : {
0 commit comments