From b2f497b100b7b94a07a22d594b26cf14e89273ae Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Tue, 12 Jun 2018 19:02:02 +0200 Subject: [PATCH] batch DOM reads from query field typeahead --- public/app/containers/Explore/QueryField.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/app/containers/Explore/QueryField.tsx b/public/app/containers/Explore/QueryField.tsx index f241e9f062a..bbfbb067d0b 100644 --- a/public/app/containers/Explore/QueryField.tsx +++ b/public/app/containers/Explore/QueryField.tsx @@ -522,10 +522,17 @@ class QueryField extends React.Component { // 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`; + }); } };