From 23008038b77455636c830870db6e24e2647ec56b Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Mon, 12 Sep 2022 23:09:15 -0400 Subject: [PATCH] (core) When managing focus, don't auto-scroll Summary: When Grist is embedded, calls to focus() cause the outer page to scroll to the embed iframe. Because this happens automatically on load, this cause the page to jump to the embed (not consistent across browsers, but at least in Chrome on Windows). This change changes the automatic focus() calls to avoid scrolling. In the normal app, it should make no difference; in embedded context, this avoids the unexpected scrolling of the parent page. Test Plan: Tested manually, with Anais's help: in her browser, embedded Grist consistently caused the page to jump to the embed before the change, and not after. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3631 --- app/client/lib/FocusLayer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/lib/FocusLayer.ts b/app/client/lib/FocusLayer.ts index 3d2330fc..fbce5b54 100644 --- a/app/client/lib/FocusLayer.ts +++ b/app/client/lib/FocusLayer.ts @@ -82,7 +82,7 @@ class FocusLayerManager extends Disposable { this._focusLayers.push(layer); // Move the focus to the new layer. Not just grabFocus, because if the focus is on the previous // layer's defaultFocusElem, the new layer might consider it "allowed" and never get the focus. - setTimeout(() => layer.defaultFocusElem.focus(), 0); + setTimeout(() => layer.defaultFocusElem.focus({preventScroll: true}), 0); } public removeLayer(layer: FocusLayer) { @@ -121,7 +121,7 @@ class FocusLayerManager extends Disposable { watchElementForBlur(document.activeElement, () => this.grabFocus()); layer.onDefaultBlur(); } else { - layer.defaultFocusElem.focus(); + layer.defaultFocusElem.focus({preventScroll: true}); layer.onDefaultFocus(); } }