Scroll on element focus

This commit is contained in:
Ian Gulliver
2019-05-27 03:29:43 +00:00
parent f9df134898
commit 549c6abedc

View File

@@ -92,9 +92,6 @@ class Editor {
return;
}
elem.focus();
elem.scrollIntoView({
block: 'center',
});
}
startEdit() {
@@ -237,6 +234,7 @@ class Node {
this.elem_ = document.createElement('li');
this.elem_.innerText = 'Node: ';
this.elem_.tabIndex = 0;
this.elem_.addEventListener('focus', () => { this.onElemFocus(); });
this.input_ = document.createElement('input');
this.input_.type = 'text';
@@ -264,10 +262,14 @@ class Node {
onInputBlur() {
if (this.input_.value.length == 0) {
// this.elem_.remove();
this.elem_.remove();
}
}
onElemFocus() {
this.elem_.scrollIntoView({block: 'center'});
}
static addBefore(container, elem) {
let node = new Node();
container.insertBefore(node.elem_, elem);
@@ -286,6 +288,7 @@ class Group {
this.elem_ = document.createElement('li');
this.elem_.innerText = 'Group: ';
this.elem_.tabIndex = 0;
this.elem_.addEventListener('focus', () => { this.onElemFocus(); });
this.input_ = document.createElement('input');
this.input_.type = 'text';
@@ -318,6 +321,10 @@ class Group {
}
}
onElemFocus() {
this.elem_.scrollIntoView({block: 'center'});
}
static addBefore(container, elem) {
let group = new Group();
container.insertBefore(group.elem_, elem);