Skip to content

Commit

Permalink
Fix scrolling to the inserted block issue in the iFramed block editor (
Browse files Browse the repository at this point in the history
…#31448)

This PR patches the package by checking whether the container is an iframe window. In that case it scrolls the scrollingElement instead of the window. We can't scroll the iframe window because it's an iframe so the typical window.scrollTo() doesn't work.
  • Loading branch information
david-szabo97 authored May 14, 2021
1 parent c8512db commit 5dec957
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export function useScrollIntoView( clientId ) {
return;
}

const scrollContainer = getScrollContainer( extentNode );
const scrollContainer =
getScrollContainer( extentNode ) ||
extentNode.ownerDocument.defaultView;

// If there's no scroll container, it follows that there's no scrollbar
// and thus there's no need to try to scroll into view.
Expand Down
25 changes: 25 additions & 0 deletions patches/dom-scroll-into-view+1.2.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/node_modules/dom-scroll-into-view/lib/dom-scroll-into-view.js b/node_modules/dom-scroll-into-view/lib/dom-scroll-into-view.js
index 557ed5c..23dfbad 100644
--- a/node_modules/dom-scroll-into-view/lib/dom-scroll-into-view.js
+++ b/node_modules/dom-scroll-into-view/lib/dom-scroll-into-view.js
@@ -21,6 +21,7 @@ function scrollIntoView(elem, container, config) {
allowHorizontalScroll = allowHorizontalScroll === undefined ? true : allowHorizontalScroll;

var isWin = util.isWindow(container);
+ var isFramed = !!(isWin && container.frameElement);
var elemOffset = util.offset(elem);
var eh = util.outerHeight(elem);
var ew = util.outerWidth(elem);
@@ -35,7 +36,11 @@ function scrollIntoView(elem, container, config) {
var ww = undefined;
var wh = undefined;

- if (isWin) {
+ if (isFramed) {
+ container = container.document.scrollingElement || container.document.body;
+ }
+
+ if (isWin || isFramed) {
win = container;
wh = util.height(win);
ww = util.width(win);

0 comments on commit 5dec957

Please sign in to comment.