Skip to content

Commit 217981e

Browse files
nadalabaMiodec
andauthored
fix(wordsInput): clamp #wordsInput from the left to #wordsWrapper (@nadalaba) (monkeytypegame#6637)
### Description In RTL tape mode (which will be a reality after monkeytypegame#5748), if a long word is wider than the #wordsWrapper, then #wordsInput may overflow to the left causing a horizontal scroll to keep it in view. This PR prevents its left edge from overflowing the #wordsWrapper. Co-authored-by: Jack <[email protected]>
1 parent 896c065 commit 217981e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

frontend/src/ts/test/test-ui.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,7 @@ export async function updateWordsInputPosition(initial = false): Promise<void> {
456456
activeWord.offsetTop + letterHeight / 2 - el.offsetHeight / 2 + 1; //+1 for half of border
457457

458458
if (Config.tapeMode !== "off") {
459-
const wordsWrapperWidth = (
460-
document.querySelector("#wordsWrapper") as HTMLElement
461-
).offsetWidth;
462-
el.style.maxWidth =
463-
wordsWrapperWidth * (1 - Config.tapeMargin / 100) + "px";
459+
el.style.maxWidth = `${100 - Config.tapeMargin}%`;
464460
} else {
465461
el.style.maxWidth = "";
466462
}
@@ -483,7 +479,7 @@ export async function updateWordsInputPosition(initial = false): Promise<void> {
483479
if (activeWord.offsetWidth < letterHeight && isLanguageRTL) {
484480
el.style.left = activeWord.offsetLeft - letterHeight + "px";
485481
} else {
486-
el.style.left = activeWord.offsetLeft + "px";
482+
el.style.left = Math.max(0, activeWord.offsetLeft) + "px";
487483
}
488484
}
489485

0 commit comments

Comments
 (0)