Skip to content

Commit ac3aed6

Browse files
committed
feat(editor): allow tabbing between stop times
1 parent c1d9043 commit ac3aed6

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

lib/editor/components/timetable/EditableCell.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { TIMETABLE_FORMATS } from '../../util/timetable'
99
*/
1010
export default class EditableCell extends Component {
1111
static propTypes = {
12-
isEditing: PropTypes.bool
12+
isEditing: PropTypes.bool,
13+
offsetScrollCol: PropTypes.func.isRequired
1314
}
1415

1516
state = {
@@ -67,7 +68,8 @@ export default class EditableCell extends Component {
6768
onRight,
6869
onRowSelect,
6970
onUp,
70-
renderTime
71+
renderTime,
72+
offsetScrollCol
7173
} = this.props
7274
const {isEditing} = this.state
7375
switch (evt.keyCode) {
@@ -109,19 +111,17 @@ export default class EditableCell extends Component {
109111
}
110112
break
111113
case 9: // Tab
114+
// save and advance to next cell if editing
115+
this.save()
116+
offsetScrollCol(evt.shiftKey ? -1 : 1)
112117
evt.preventDefault()
113-
// handle shift
114-
if (evt.shiftKey) {
115-
this.save(evt)
116-
} else {
117-
this.save(evt)
118-
}
118+
evt.stopPropagation()
119119
break
120120
case 27: // Esc
121121
this.cancel()
122122
break
123123
case 39: // right
124-
// do nothing if cell is being edited
124+
// cancel event propogation if cell is being edited
125125
if (isEditing) {
126126
evt.stopPropagation()
127127
return
@@ -168,6 +168,10 @@ export default class EditableCell extends Component {
168168
_onOuterKeyDown = (e) => {
169169
if (document.activeElement === e.target && e.which === 13) {
170170
this.handleClick(e)
171+
} else if (e.keyCode === 9) {
172+
this.props.offsetScrollCol(e.shiftKey ? -1 : 1)
173+
e.stopPropagation()
174+
e.preventDefault()
171175
}
172176
}
173177

@@ -213,6 +217,7 @@ export default class EditableCell extends Component {
213217
}
214218
}
215219
}
220+
216221
cellRenderer (value) {
217222
if (this.props.cellRenderer) {
218223
return this.props.cellRenderer(this.props.column, value)
@@ -311,7 +316,8 @@ export default class EditableCell extends Component {
311316
onFocus={this._onInputFocus}
312317
onBlur={this.cancel} />
313318
: <div
314-
style={divStyle}>
319+
style={divStyle}
320+
>
315321
{this.cellRenderer(this.state.data)}
316322
</div>
317323
return (

lib/editor/components/timetable/TimetableGrid.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ import objectPath from 'object-path'
77

88
import HeaderCell from './HeaderCell'
99
import 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

1228
export 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

Comments
 (0)