Skip to content

Commit a46e053

Browse files
authored
Merge pull request #182 from devforth/list-pagination
feat: enhance pagination input handling
2 parents 8b2cf79 + 06e24c6 commit a46e053

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@
227227
contenteditable="true"
228228
class="min-w-10 outline-none inline-block w-auto min-w-10 py-1.5 px-3 text-sm text-center text-gray-700 border border-gray-300 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800 z-10"
229229
@keydown="onPageKeydown($event)"
230-
@input="page = parseInt($event.target.innerText) || ''"
230+
@input="onPageInput($event)"
231+
@blur="validatePageInput()"
231232
>
232233
{{ pageInput }}
233234
</div>
@@ -355,6 +356,10 @@ async function onPageKeydown(event) {
355356
(!['Backspace', 'ArrowRight', 'ArrowLeft'].includes(event.code)
356357
&& isNaN(String.fromCharCode(event.keyCode)))) {
357358
event.preventDefault();
359+
if (event.code === 'Enter') {
360+
validatePageInput();
361+
event.target.blur();
362+
}
358363
}
359364
}
360365
@@ -575,6 +580,16 @@ async function startCustomAction(actionId, row) {
575580
}
576581
}
577582
583+
function onPageInput(event) {
584+
pageInput.value = event.target.innerText;
585+
}
586+
587+
function validatePageInput() {
588+
const newPage = parseInt(pageInput.value) || 1;
589+
const validPage = Math.max(1, Math.min(newPage, totalPages.value));
590+
page.value = validPage;
591+
pageInput.value = validPage.toString();
592+
}
578593
579594
</script>
580595

0 commit comments

Comments
 (0)