From fd68b5c79df0e2cbdf7501939cdb7661b6b006bb Mon Sep 17 00:00:00 2001 From: MattMo Date: Mon, 11 Mar 2024 12:28:57 -0700 Subject: [PATCH] Added code to reset all scroll positions when a route is shown. This way when a route and new data is rendered it's rendered with default scroll positions. --- ignite-html-router.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ignite-html-router.js b/ignite-html-router.js index 636f601..d57f978 100644 --- a/ignite-html-router.js +++ b/ignite-html-router.js @@ -57,6 +57,17 @@ IgniteTemplate.prototype.route = function (routes, showCallback = null, hideCall //Show the route element. this.element.style.removeProperty("display"); + //Reset scroll bars for route + this.element.scrollTop = 0; + this.element.scrollLeft = 0; + + //Reset scroll bars for all elements inside route + [...this.element.querySelectorAll("*")].forEach(element => { + element.scrollTop = 0; + element.scrollLeft = 0; + }); + + //Invoke show callback if any. if (showCallback) { showCallback(matchedRoute, (event && event.data ? event.data : data), back); }