mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
wip: minimal keyboard navigation in table editor
This commit is contained in:
parent
f62f3b4ab9
commit
f1c34f9d27
1 changed files with 50 additions and 5 deletions
|
@ -226,16 +226,61 @@ export default class TableEditor extends WithTemplate {
|
||||||
input.focus()
|
input.focus()
|
||||||
input.addEventListener('blur', () => {
|
input.addEventListener('blur', () => {
|
||||||
cell.innerHTML = feature.properties[property] || ''
|
cell.innerHTML = feature.properties[property] || ''
|
||||||
|
cell.focus()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(event) {
|
onKeyDown(event) {
|
||||||
|
// Only on data <td>, not inputs or anything else
|
||||||
|
if (!event.target.dataset.property) return
|
||||||
const key = event.key
|
const key = event.key
|
||||||
if (key === 'Enter') {
|
const actions = {
|
||||||
const current = this.getFocus()
|
Enter: () => this.editCurrent(),
|
||||||
if (current) {
|
ArrowRight: () => this.moveRight(),
|
||||||
this.editCell(current)
|
ArrowLeft: () => this.moveLeft(),
|
||||||
}
|
ArrowUp: () => this.moveUp(),
|
||||||
|
ArrowDown: () => this.moveDown(),
|
||||||
|
}
|
||||||
|
if (key in actions) {
|
||||||
|
actions[key]()
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
editCurrent() {
|
||||||
|
const current = this.getFocus()
|
||||||
|
if (current) {
|
||||||
|
this.editCell(current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveRight() {
|
||||||
|
const cell = this.getFocus()
|
||||||
|
if (cell.nextSibling) cell.nextSibling.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
moveLeft() {
|
||||||
|
const cell = this.getFocus()
|
||||||
|
if (cell.previousSibling) cell.previousSibling.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
moveDown() {
|
||||||
|
const cell = this.getFocus()
|
||||||
|
const tr = cell.closest('tr')
|
||||||
|
const property = cell.dataset.property
|
||||||
|
const nextTr = tr.nextSibling
|
||||||
|
if (nextTr) {
|
||||||
|
nextTr.querySelector(`td[data-property="${property}"`).focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveUp() {
|
||||||
|
const cell = this.getFocus()
|
||||||
|
const tr = cell.closest('tr')
|
||||||
|
const property = cell.dataset.property
|
||||||
|
const previousTr = tr.previousSibling
|
||||||
|
if (previousTr) {
|
||||||
|
previousTr.querySelector(`td[data-property="${property}"`).focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue