Skip to content

Commit 198d7e0

Browse files
committed
feat(editor): better tab handling in timetable grid
1 parent a4d9ca8 commit 198d7e0

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

lib/editor/components/timetable/EditableCell.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export default class EditableCell extends Component {
127127
return
128128
}
129129

130+
// update scroll position in TimetableGrid
131+
offsetScrollCol(1)
132+
130133
// save and move to next cell if at end of string
131134
if (input.selectionStart === input.value.length) {
132135
this.save(evt)
@@ -141,6 +144,9 @@ export default class EditableCell extends Component {
141144
return
142145
}
143146

147+
// update scroll position in TimetableGrid
148+
offsetScrollCol(-1)
149+
144150
// save and move to next cell if at start of string
145151
if (input.selectionStart === 0 && input.selectionEnd === input.value.length) {
146152
this.save(evt)
@@ -166,12 +172,23 @@ export default class EditableCell extends Component {
166172
}
167173

168174
_onOuterKeyDown = (e) => {
169-
if (document.activeElement === e.target && e.which === 13) {
170-
this.handleClick(e)
171-
} else if (e.keyCode === 9) {
172-
this.props.offsetScrollCol(e.shiftKey ? -1 : 1)
173-
e.stopPropagation()
174-
e.preventDefault()
175+
const {offsetScrollCol} = this.props
176+
switch (e.keyCode) {
177+
case 9: // tab
178+
// update scroll position in TimetableGrid
179+
offsetScrollCol(e.shiftKey ? -1 : 1)
180+
// prevent other listeners and default browser tabbing
181+
e.stopPropagation()
182+
e.preventDefault()
183+
break
184+
case 37: // left
185+
// update scroll position in TimetableGrid
186+
offsetScrollCol(-1)
187+
break
188+
case 39: // right
189+
// update scroll position in TimetableGrid
190+
offsetScrollCol(1)
191+
break
175192
}
176193
}
177194

lib/editor/components/timetable/TimetableGrid.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ export default class TimetableGrid extends Component {
4343
handleKeyPress = (evt) => {
4444
const {activeCell, setActiveCell, scrollToColumn, scrollToRow} = this.props
4545
switch (evt.keyCode) {
46+
case 8: // DELETE
47+
// TODO: add delete cell value
48+
// updateCellValue('', rowIndex, `${scrollToRow}.${col.key}`)
49+
break
50+
case 9: // tab
51+
this.offsetScrollCol(evt.shiftKey ? -1 : 1)
52+
evt.preventDefault()
53+
break
4654
case 13: // Enter
4755
if (!activeCell) {
4856
return setActiveCell(`${scrollToRow}-${scrollToColumn}`)
4957
} else {
5058
return setActiveCell(null)
5159
}
52-
case 8: // DELETE
53-
// TODO: add delete cell value
54-
// updateCellValue('', rowIndex, `${scrollToRow}.${col.key}`)
55-
break
5660
case 67:
5761
// handle copy
5862
if (evt.ctrlKey) {
@@ -166,27 +170,26 @@ export default class TimetableGrid extends Component {
166170
const isInvalid = isTimeFormat(col.type) && val >= 0 && val < previousValue && val !== null
167171
return (
168172
<EditableCell
169-
key={key}
170-
onClick={updateScroll}
171-
// duplicateLeft={(evt) => updateCellValue(previousValue, rowIndex, `${rowIndex}.${col.key}`)}
173+
cellRenderer={getCellRenderer}
174+
column={col}
175+
columnIndex={columnIndex} // pass original index to prevent issues with updateScroll/scrollsync
176+
data={val}
172177
handlePastedRows={this.handlePastedRows}
178+
hideDepartureTimes={hideDepartureTimes}
173179
invalidData={isInvalid}
174180
isEditing={isEditing}
175-
isSelected={rowIsChecked}
176181
isFocused={isFocused}
177-
hideDepartureTimes={hideDepartureTimes}
182+
isSelected={rowIsChecked}
183+
key={key}
178184
lightText={col.type === 'DEPARTURE_TIME'}
185+
offsetScrollCol={this.offsetScrollCol}
186+
onChange={this._onCellChange}
187+
onClick={updateScroll}
188+
onStopEditing={this.handleEndEditing}
179189
placeholder={col.placeholder}
180190
renderTime={isTimeFormat(col.type)}
181-
cellRenderer={getCellRenderer}
182-
data={val}
183-
column={col}
184-
columnIndex={columnIndex} // pass original index to prevent issues with updateScroll/scrollsync
185191
rowIndex={rowIndex}
186192
style={style}
187-
onStopEditing={this.handleEndEditing}
188-
onChange={this._onCellChange}
189-
offsetScrollCol={this.offsetScrollCol}
190193
/>
191194
)
192195
}

0 commit comments

Comments
 (0)