diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/overrides.js b/bundles/AdminBundle/Resources/public/js/pimcore/overrides.js index b9ce2f7216c..69fa4948a31 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/overrides.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/overrides.js @@ -1203,6 +1203,32 @@ Ext.override(Ext.picker.Date, { } }); +function isElementInTheViewport(domElement) { + if (domElement && typeof domElement.getBoundingClientRect === "function") { + const rect = domElement.getBoundingClientRect(); + if (rect) { + return ( + rect["top"] < window.innerHeight && + rect["bottom"] > 0 + ); + } + } + return false; +} + +Ext.override(Ext.dom.Element, { + focus: function (defer, dom) { + var me = this; + + dom = dom || me.dom; + + dom.focus({ + preventScroll: isElementInTheViewport(dom) + }); + + return me; + } +}); /** * A specialized {@link Ext.view.BoundListKeyNav} implementation for navigating in the quicksearch.