|
208 | 208 | <div |
209 | 209 | contenteditable="true" |
210 | 210 | 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" |
| 211 | + @keydown="onPageKeydown($event)" |
211 | 212 | @input="page = parseInt($event.target.innerText) || ''" |
212 | 213 | > |
213 | 214 | {{ pageInput }} |
|
271 | 272 | <script setup lang="ts"> |
272 | 273 |
|
273 | 274 |
|
274 | | -import { computed, onMounted, ref, watch, useTemplateRef, type Ref } from 'vue'; |
| 275 | +import { computed, onMounted, ref, watch, useTemplateRef, nextTick, type Ref } from 'vue'; |
275 | 276 | import { callAdminForthApi } from '@/utils'; |
276 | 277 | import { useI18n } from 'vue-i18n'; |
277 | 278 | import ValueRenderer from '@/components/ValueRenderer.vue'; |
@@ -329,6 +330,14 @@ const to = computed(() => Math.min((page.value || 1) * props.pageSize, props.tot |
329 | 330 | watch(() => page.value, (newPage) => { |
330 | 331 | emits('update:page', newPage); |
331 | 332 | }); |
| 333 | +async function onPageKeydown(event) { |
| 334 | + // page input should accept only numbers, arrow keys and backspace |
| 335 | + if (['Enter', 'Space'].includes(event.code) || |
| 336 | + (!['Backspace', 'ArrowRight', 'ArrowLeft'].includes(event.code) |
| 337 | + && isNaN(String.fromCharCode(event.keyCode)))) { |
| 338 | + event.preventDefault(); |
| 339 | + } |
| 340 | +} |
332 | 341 |
|
333 | 342 | watch(() => sort.value, (newSort) => { |
334 | 343 | emits('update:sort', newSort); |
|
0 commit comments