@@ -103,7 +103,31 @@ const initialVariants = [{ grouped: false }]
103103
104104const makeGroups = () => ({ groupLabels: [' C' , ' D' , ' Others' ], groupCounts: [1 ,1 ,12 ] })
105105
106- ;
106+ /**
107+ * @param direction : ArrowUp / ArrowRight: -1, ArrowDown / ArrowLeft: 1
108+ * @param items : Array (optional)
109+ */
110+ const handleShiftArrow = (direction , items = []) => {
111+ const allItems = items .length === 0 ? itemsListRef .current : items
112+
113+ let newFocusedIndex = focusedIndex
114+
115+ if (direction === - 1 ) {
116+ newFocusedIndex = Math .max (0 , focusedIndex - 1 )
117+ } else if (direction === 1 ) {
118+ newFocusedIndex = Math .min (allItems .length - 1 , focusedIndex + 1 )
119+ }
120+
121+ setFocusedIndex (newFocusedIndex)
122+ setIsKeyboardNavigating (true )
123+
124+ const anchorIndex =
125+ lastSelectedIndex !== null ? lastSelectedIndex : focusedIndex
126+ if (lastSelectedIndex === null ) {
127+ setLastSelectedIndex (focusedIndex)
128+ }
129+ selectExactRange (allItems, anchorIndex, newFocusedIndex)
130+ }
107131
108132< Variants initialVariants= {initialVariants} screenshotAllVariants>
109133 {variant => (
@@ -123,6 +147,7 @@ const makeGroups = () => ({ groupLabels: ['C', 'D', 'Others'], groupCounts: [1,1
123147 onLongPress : (row , column ) => { console .info (` long press on cell. Row ${ row[' id' ]} , Column ${ column[' id' ]} ` ) },
124148 },
125149 }}
150+ handleShiftArrow= {handleShiftArrow}
126151 / >
127152 < / div>
128153 )}
0 commit comments