From 6a31814900321e9278511ceb1fb5cfecd1bdb2b6 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Wed, 18 Mar 2026 11:39:53 +0300 Subject: [PATCH] Fix scroll position reset when closing modals - Use { behavior: 'instant' } in unlockBody scrollTo to override CSS scroll-behavior: smooth on html element - Use { preventScroll: true } on focus() restore in Modal.forceClose - Add overflow-y: scroll to body.modal-open to prevent scrollbar shift Co-Authored-By: Claude Opus 4.6 (1M context) --- server/src/wled_controller/static/css/base.css | 1 + server/src/wled_controller/static/js/core/modal.js | 2 +- server/src/wled_controller/static/js/core/ui.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/wled_controller/static/css/base.css b/server/src/wled_controller/static/css/base.css index 4e9996b..799f48d 100644 --- a/server/src/wled_controller/static/css/base.css +++ b/server/src/wled_controller/static/css/base.css @@ -93,6 +93,7 @@ body { body.modal-open { position: fixed; width: 100%; + overflow-y: scroll; /* keep scrollbar gutter to prevent layout shift */ } /* ── Ambient animated background ── */ diff --git a/server/src/wled_controller/static/js/core/modal.js b/server/src/wled_controller/static/js/core/modal.js index 47bd1eb..6b5c7a6 100644 --- a/server/src/wled_controller/static/js/core/modal.js +++ b/server/src/wled_controller/static/js/core/modal.js @@ -43,7 +43,7 @@ export class Modal { this.onForceClose(); Modal._stack = Modal._stack.filter(m => m !== this); if (this._previousFocus && typeof this._previousFocus.focus === 'function') { - this._previousFocus.focus(); + this._previousFocus.focus({ preventScroll: true }); this._previousFocus = null; } } diff --git a/server/src/wled_controller/static/js/core/ui.js b/server/src/wled_controller/static/js/core/ui.js index 4243f19..719cc5f 100644 --- a/server/src/wled_controller/static/js/core/ui.js +++ b/server/src/wled_controller/static/js/core/ui.js @@ -84,7 +84,7 @@ export function unlockBody() { if (_lockCount === 0) { document.body.classList.remove('modal-open'); document.body.style.top = ''; - window.scrollTo(0, _savedScrollY); + window.scrollTo({ top: _savedScrollY, behavior: 'instant' }); } }