jsdialog: scroll treeview to selected entry

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I7c88df039fc0358b3444be3552f2e200ee3bf71f
This commit is contained in:
Szymon Kłos 2023-01-05 15:04:16 +01:00 committed by Szymon Kłos
parent 8371ce4437
commit b338c3faec

View file

@ -368,6 +368,8 @@ function _treelistboxControl(parentContainer, data, builder) {
tr.tabIndex = 0;
_headerlistboxEntry(tr, data, data.entries[i], builder);
}
var firstSelected = tbody.querySelector('.ui-listview-entry.selected');
} else {
// tree view
var ul = L.DomUtil.create('ul', builder.options.cssClass, tbody);
@ -375,6 +377,24 @@ function _treelistboxControl(parentContainer, data, builder) {
for (i in data.entries) {
_treelistboxEntry(ul, data, data.entries[i], builder);
}
firstSelected = tbody.querySelector('.ui-treeview-entry.selected');
}
if (firstSelected) {
var observer = new IntersectionObserver(function (entries, observer) {
entries.forEach(function (entry) {
if (entry.intersectionRatio > 0) {
if (isHeaderListBox)
table.scrollTop = firstSelected.offsetTop - tbody.offsetTop;
else
table.scrollTop = firstSelected.parentNode.offsetTop - tbody.offsetTop;
observer.disconnect();
}
});
});
observer.observe(tbody);
}
table.filterEntries = function (filter) {