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) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 11:39:53 +03:00
parent ea9b05733b
commit 6a31814900
3 changed files with 3 additions and 2 deletions

View File

@@ -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 ── */

View File

@@ -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;
}
}

View File

@@ -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' });
}
}