@@ -34,7 +34,10 @@ import {
3434 GridTokenMouseHandler ,
3535} from './mouse-handlers' ;
3636import './Grid.scss' ;
37- import KeyHandler , { GridKeyboardEvent } from './KeyHandler' ;
37+ import KeyHandler , {
38+ GridKeyHandlerFunctionName ,
39+ GridKeyboardEvent ,
40+ } from './KeyHandler' ;
3841import {
3942 EditKeyHandler ,
4043 PasteKeyHandler ,
@@ -342,7 +345,9 @@ class Grid extends PureComponent<GridProps, GridState> {
342345 this . handleEditCellChange = this . handleEditCellChange . bind ( this ) ;
343346 this . handleEditCellCommit = this . handleEditCellCommit . bind ( this ) ;
344347 this . handleDoubleClick = this . handleDoubleClick . bind ( this ) ;
348+ this . notifyKeyboardHandlers = this . notifyKeyboardHandlers . bind ( this ) ;
345349 this . handleKeyDown = this . handleKeyDown . bind ( this ) ;
350+ this . handleKeyUp = this . handleKeyUp . bind ( this ) ;
346351 this . handleMouseDown = this . handleMouseDown . bind ( this ) ;
347352 this . handleMouseDrag = this . handleMouseDrag . bind ( this ) ;
348353 this . handleMouseMove = this . handleMouseMove . bind ( this ) ;
@@ -1715,14 +1720,20 @@ class Grid extends PureComponent<GridProps, GridState> {
17151720 }
17161721
17171722 /**
1718- * Handle a key down event from the keyboard. Pass the event to the registered keyboard handlers until one handles it.
1719- * @param event Keyboard event
1723+ * Notify all of the keyboard handlers for this grid of a keyboard event.
1724+ * @param functionName The name of the function in the keyboard handler to call
1725+ * @param event The keyboard event to notify
17201726 */
1721- handleKeyDown ( event : GridKeyboardEvent ) : void {
1727+ notifyKeyboardHandlers (
1728+ functionName : GridKeyHandlerFunctionName ,
1729+ event : GridKeyboardEvent
1730+ ) : void {
17221731 const keyHandlers = this . getKeyHandlers ( ) ;
17231732 for ( let i = 0 ; i < keyHandlers . length ; i += 1 ) {
17241733 const keyHandler = keyHandlers [ i ] ;
1725- const result = keyHandler . onDown ( event , this ) ;
1734+ const result =
1735+ keyHandler [ functionName ] != null &&
1736+ keyHandler [ functionName ] ( event , this ) ;
17261737 if ( result !== false ) {
17271738 const options = result as EventHandlerResultOptions ;
17281739 if ( options ?. stopPropagation ?? true ) event . stopPropagation ( ) ;
@@ -1732,6 +1743,14 @@ class Grid extends PureComponent<GridProps, GridState> {
17321743 }
17331744 }
17341745
1746+ handleKeyDown ( event : GridKeyboardEvent ) : void {
1747+ this . notifyKeyboardHandlers ( 'onDown' , event ) ;
1748+ }
1749+
1750+ handleKeyUp ( event : GridKeyboardEvent ) : void {
1751+ this . notifyKeyboardHandlers ( 'onUp' , event ) ;
1752+ }
1753+
17351754 /**
17361755 * Notify all of the mouse handlers for this grid of a mouse event.
17371756 * @param functionName The name of the function in the mouse handler to call
@@ -2229,6 +2248,7 @@ class Grid extends PureComponent<GridProps, GridState> {
22292248 onContextMenu = { this . handleContextMenu }
22302249 onDoubleClick = { this . handleDoubleClick }
22312250 onKeyDown = { this . handleKeyDown }
2251+ onKeyUp = { this . handleKeyUp }
22322252 onMouseDown = { this . handleMouseDown }
22332253 onMouseMove = { this . handleMouseMove }
22342254 onMouseLeave = { this . handleMouseLeave }
0 commit comments