@@ -16,6 +16,12 @@ export interface DraggableGraphProps extends ControlProps {
1616 handleStartAnimationRef ?: ( startAnimation : ( duration : number ) => void ) => void ;
1717}
1818
19+ const getSliderStepValue = ( min : number , max : number ) => {
20+ const range = max - min ;
21+ // Assumes slider values are always integers.
22+ return Math . max ( 1 , Math . floor ( range / 10 ) ) ;
23+ }
24+
1925export const DraggableGraph = ( props : DraggableGraphProps ) => {
2026 const {
2127 interpolation,
@@ -113,16 +119,37 @@ export const DraggableGraph = (props: DraggableGraphProps) => {
113119 } ;
114120
115121 ref . onkeydown = ev => {
116- const step = ( max - min ) / 100 ;
117- if ( ev . code === "ArrowDown" || ev . code === "ArrowLeft" ) {
118- onPointChange ( index , Math . max ( min , points [ index ] - step ) ) ;
119- ev . stopPropagation ( ) ;
120- ev . preventDefault ( ) ;
121- } else if ( ev . code === "ArrowUp" || ev . code === "ArrowRight" ) {
122- onPointChange ( index , Math . min ( max , points [ index ] + step ) ) ;
123- ev . stopPropagation ( ) ;
122+ const key = ev . key ;
123+ if ( [ "ArrowUp" , "ArrowDown" , "ArrowLeft" , "ArrowRight" , "PageUp" , "PageDown" , "Home" , "End" ] . includes ( key ) ) {
124124 ev . preventDefault ( ) ;
125- }
125+ }
126+ const currentValue = points [ index ]
127+ switch ( key ) {
128+ case "ArrowDown" :
129+ case "ArrowLeft" : {
130+ return onPointChange ( index , Math . max ( min , currentValue - 1 ) ) ;
131+ }
132+ case "ArrowUp" :
133+ case "ArrowRight" : {
134+ return onPointChange ( index , Math . min ( max , currentValue + 1 ) ) ;
135+ }
136+ case "Home" : {
137+ return onPointChange ( index , min ) ;
138+ }
139+ case "End" : {
140+ return onPointChange ( index , max ) ;
141+ }
142+ case "PageDown" : {
143+ const step = getSliderStepValue ( min , max ) ;
144+ const value = currentValue - step ;
145+ return onPointChange ( index , Math . max ( min , value ) ) ;
146+ }
147+ case "PageUp" : {
148+ const step = getSliderStepValue ( min , max ) ;
149+ const value = currentValue + step ;
150+ return onPointChange ( index , Math . min ( max , value ) ) ;
151+ }
152+ }
126153 }
127154 } ) ;
128155 } , [ dragIndex , onPointChange ] )
0 commit comments