Skip to content

Commit 8d73ffd

Browse files
Bismay5467Dun-sin
andauthored
fix: prevent overflow for larger input values (#503)
Co-authored-by: Dunsin <[email protected]>
1 parent df3659c commit 8d73ffd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/pages/grid-generator.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ const attribute = 'grid-generators';
2121
const getCssOrTailwindDropdownElement = getCssOrTailwindDropdown(attribute);
2222
const showCopyClass = 'show-css-tailwind';
2323

24+
function areInputsValid() {
25+
const noOfColumns = getNumberOfColumns(attribute);
26+
const noOfRows = getNumberOfRows(attribute);
27+
28+
const isColumnInputValid =
29+
noOfColumns.value.length > 0
30+
? parseInt(noOfColumns.value) >= 1 && parseInt(noOfColumns.value) <= 100
31+
: true;
32+
const isRowInputValid =
33+
noOfRows.value.length > 0
34+
? parseInt(noOfRows.value) >= 1 && parseInt(noOfRows.value) <= 100
35+
: true;
36+
37+
if (isColumnInputValid && isRowInputValid) return true;
38+
39+
showPopup(
40+
'Limit Exceeded',
41+
'The input value should be within 1 and 100.',
42+
'error'
43+
);
44+
45+
return false;
46+
}
47+
2448
export function gridGenerator(): void {
2549
const noOfColumns = getNumberOfColumns(attribute);
2650
const noOfRows = getNumberOfRows(attribute);
@@ -44,6 +68,7 @@ export function gridGenerator(): void {
4468
allGridInputFields[index].textContent = `${input.value}px`;
4569
}
4670
input.addEventListener('input', () => {
71+
if (areInputsValid() === false) return;
4772
preview.style.display = 'grid';
4873
preview.style.gridTemplateColumns = getGridColValue();
4974
preview.style.gridTemplateRows = getGridRowValue();

0 commit comments

Comments
 (0)