batch DOM reads from query field typeahead

This commit is contained in:
David Kaltschmidt
2018-06-14 16:20:21 +01:00
parent 73ddf2c3ed
commit b2f497b100
+10 -3
View File
@@ -522,10 +522,17 @@ class QueryField extends React.Component<any, any> {
// Align menu overlay to editor node
if (node) {
// Read from DOM
const rect = node.parentElement.getBoundingClientRect();
menu.style.opacity = 1;
menu.style.top = `${rect.top + window.scrollY + rect.height + 4}px`;
menu.style.left = `${rect.left + window.scrollX - 2}px`;
const scrollX = window.scrollX;
const scrollY = window.scrollY;
// Write DOM
requestAnimationFrame(() => {
menu.style.opacity = 1;
menu.style.top = `${rect.top + scrollY + rect.height + 4}px`;
menu.style.left = `${rect.left + scrollX - 2}px`;
});
}
};