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:
@@ -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 ── */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user