@@ -7,7 +7,23 @@ import objectPath from 'object-path'
77
88import HeaderCell from './HeaderCell'
99import EditableCell from './EditableCell'
10- import { getCellRenderer , getHeaderColumns , isTimeFormat , parseTime , OVERSCAN_ROW_COUNT , OVERSCAN_COLUMN_COUNT , HEADER_GRID_WRAPPER_STYLE , HEADER_GRID_STYLE , LEFT_GRID_WRAPPER_STYLE , LEFT_COLUMN_WIDTH , ROW_HEIGHT , LEFT_GRID_STYLE , TOP_LEFT_STYLE , MAIN_GRID_WRAPPER_STYLE , WRAPPER_STYLE } from '../../util/timetable'
10+ import {
11+ getCellRenderer ,
12+ getHeaderColumns ,
13+ isTimeFormat ,
14+ parseTime ,
15+ OVERSCAN_ROW_COUNT ,
16+ OVERSCAN_COLUMN_COUNT ,
17+ HEADER_GRID_WRAPPER_STYLE ,
18+ HEADER_GRID_STYLE ,
19+ LEFT_GRID_WRAPPER_STYLE ,
20+ LEFT_COLUMN_WIDTH ,
21+ ROW_HEIGHT ,
22+ LEFT_GRID_STYLE ,
23+ TOP_LEFT_STYLE ,
24+ MAIN_GRID_WRAPPER_STYLE ,
25+ WRAPPER_STYLE
26+ } from '../../util/timetable'
1127
1228export default class TimetableGrid extends Component {
1329 static propTypes = {
@@ -169,7 +185,9 @@ export default class TimetableGrid extends Component {
169185 rowIndex = { rowIndex }
170186 style = { style }
171187 onStopEditing = { this . handleEndEditing }
172- onChange = { this . _onCellChange } />
188+ onChange = { this . _onCellChange }
189+ offsetScrollCol = { this . offsetScrollCol }
190+ />
173191 )
174192 }
175193
@@ -200,9 +218,27 @@ export default class TimetableGrid extends Component {
200218 : 90
201219 }
202220
221+ /**
222+ * A helper method to move the active column a certain amount of cells left or right.
223+ * This was initially added to help with handling tab and shift + tab events.
224+ * @param {number } offset the number of columns to offset, can be positive or negative
225+ */
226+ offsetScrollCol = ( offset ) => {
227+ const { scrollToColumn, scrollToRow, updateScroll} = this . props
228+ updateScroll (
229+ scrollToRow ,
230+ Math . max ( Math . min ( scrollToColumn + offset , this . _getColumnCount ( ) - 1 ) , 0 )
231+ )
232+ }
233+
234+ _getColumnCount ( ) {
235+ const { columns, hideDepartureTimes} = this . props
236+ return hideDepartureTimes ? getHeaderColumns ( columns ) . length : columns . length
237+ }
238+
203239 render ( ) {
204240 const { onScroll, scrollLeft, scrollTop, onSectionRendered, scrollToColumn, scrollToRow} = this . props
205- const { style, data, columns, hideDepartureTimes , selected} = this . props
241+ const { style, data, columns, selected} = this . props
206242 const selectAll = selected . length === data . length
207243 const columnHeaderCount = getHeaderColumns ( columns ) . length
208244 return (
@@ -267,7 +303,7 @@ export default class TimetableGrid extends Component {
267303 ref = { Grid => { this . grid = Grid } }
268304 style = { { outline : 'none' } }
269305 columnWidth = { this . _getColumnWidth }
270- columnCount = { hideDepartureTimes ? columnHeaderCount : columns . length }
306+ columnCount = { this . _getColumnCount ( ) }
271307 height = { height }
272308 onScroll = { onScroll }
273309 overscanColumnCount = { OVERSCAN_COLUMN_COUNT }
0 commit comments