Skip to content

Commit b0d1efa

Browse files
committed
refactor: disable scrollIntoView inside modals to prevent layout clipping
1 parent 5277742 commit b0d1efa

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

web-app/js/main.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,13 @@ if (stickyFilterBar && heroSection) {
669669
modalBody.style.width = '';
670670
modalBody.style.height = '';
671671

672-
var firstChild = modalBody.firstElementChild;
673-
if (!firstChild) return;
672+
var targetEl = Array.from(modalBody.children).find(function (el) {
673+
return el.tagName.toLowerCase() !== 'style';
674+
}) || modalBody.firstElementChild;
675+
if (!targetEl) return;
674676

675-
firstChild.style.transform = '';
676-
firstChild.style.transformOrigin = '';
677+
targetEl.style.transform = '';
678+
targetEl.style.transformOrigin = '';
677679

678680
var computedStyle = window.getComputedStyle(modalContent);
679681
var paddingTop = parseFloat(computedStyle.paddingTop) || 32;
@@ -684,8 +686,8 @@ if (stickyFilterBar && heroSection) {
684686
var availableHeight = modalContent.clientHeight - paddingTop - paddingBottom;
685687
var availableWidth = modalContent.clientWidth - paddingLeft - paddingRight;
686688

687-
var contentHeight = firstChild.scrollHeight;
688-
var contentWidth = firstChild.scrollWidth;
689+
var contentHeight = targetEl.scrollHeight;
690+
var contentWidth = targetEl.scrollWidth;
689691

690692
if (contentHeight <= 0 || contentWidth <= 0) return;
691693

@@ -699,8 +701,8 @@ if (stickyFilterBar && heroSection) {
699701
}
700702

701703
// Apply scale transform and origins
702-
firstChild.style.transform = 'scale(' + zoom + ')';
703-
firstChild.style.transformOrigin = 'top center';
704+
targetEl.style.transform = 'scale(' + zoom + ')';
705+
targetEl.style.transformOrigin = 'top center';
704706

705707
// Constrain wrapper block size to prevent scroll triggering
706708
modalBody.style.height = (contentHeight * zoom) + 'px';
@@ -718,12 +720,14 @@ if (stickyFilterBar && heroSection) {
718720
}
719721

720722
var modalBody = document.getElementById('modalBody');
721-
var firstChild = modalBody ? modalBody.firstElementChild : null;
722-
if (firstChild) {
723+
var targetEl = modalBody ? Array.from(modalBody.children).find(function (el) {
724+
return el.tagName.toLowerCase() !== 'style';
725+
}) || modalBody.firstElementChild : null;
726+
if (targetEl) {
723727
modalResizeObserver = new ResizeObserver(function () {
724728
requestAnimationFrame(applyModalScaling);
725729
});
726-
modalResizeObserver.observe(firstChild);
730+
modalResizeObserver.observe(targetEl);
727731
}
728732

729733
window.addEventListener('resize', applyModalScaling);

web-app/js/projects/color-palette.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ function initColorPalette() {
713713

714714
output.style.display = 'block';
715715
controls.style.display = 'none';
716-
output.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
717716
});
718717

719718
copyBtn.addEventListener('click', () => {

web-app/js/projects/typing-speed-tester.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,6 @@ resultDetails.innerHTML = `
743743
// ensure pending state
744744
const spans = sentenceElement.querySelectorAll('span');
745745
spans.forEach(s => s.className = 'pending');
746-
if (inputElement.scrollIntoView) {
747-
inputElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
748-
}
749746
}
750747

751748
function setDifficulty(mode, { resetGame = false } = {}) {

0 commit comments

Comments
 (0)