Skip to content

Commit 0de8b7b

Browse files
authored
Merge pull request #123 from devforth/firefox-page-input-cursor-jump
fix: prevent page input cursor from jumping on input
2 parents ad42ff1 + daf34df commit 0de8b7b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
<!-- Buttons -->
190190
<button
191191
class="flex items-center py-1 px-3 gap-1 text-sm font-medium text-gray-900 focus:outline-none bg-white border-r-0 rounded-s border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
192-
@click="page--" :disabled="page <= 1">
192+
@click="page--; pageInput = page.toString();" :disabled="page <= 1">
193193
<svg class="w-3.5 h-3.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
194194
viewBox="0 0 14 10">
195195
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
@@ -201,28 +201,28 @@
201201
</button>
202202
<button
203203
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-r-0 border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
204-
@click="page = 1" :disabled="page <= 1">
204+
@click="page = 1; pageInput = page.toString();" :disabled="page <= 1">
205205
<!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
206206
1
207207
</button>
208-
<div
208+
<div
209209
contenteditable="true"
210210
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"
211211
@input="page = parseInt($event.target.innerText) || ''"
212212
>
213-
{{ page }}
213+
{{ pageInput }}
214214
</div>
215215

216216
<button
217217
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white border-l-0 border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
218-
@click="page = totalPages" :disabled="page >= totalPages">
218+
@click="page = totalPages; pageInput = page.toString();" :disabled="page >= totalPages">
219219
{{ totalPages }}
220220

221221
<!-- <IconChevronDoubleRightOutline class="w-4 h-4" /> -->
222222
</button>
223223
<button
224224
class="flex items-center py-1 px-3 gap-1 text-sm font-medium text-gray-900 focus:outline-none bg-white border-l-0 rounded-e border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
225-
@click="page++" :disabled="page >= totalPages">
225+
@click="page++; pageInput = page.toString();" :disabled="page >= totalPages">
226226
<span class="hidden sm:inline">{{ $t('Next') }}</span>
227227
<svg class="w-3.5 h-3.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
228228
viewBox="0 0 14 10">
@@ -318,6 +318,7 @@ const emits = defineEmits([
318318
]);
319319
320320
const checkboxesInternal: Ref<any[]> = ref([]);
321+
const pageInput = ref('1');
321322
const page = ref(1);
322323
const sort = ref([]);
323324
@@ -346,6 +347,9 @@ watch(() => props.sort, (newSort) => {
346347
});
347348
348349
watch(() => props.page, (newPage) => {
350+
// page.value and newPage will not be equal only on page load
351+
// this check prevents cursor jumping on manual input
352+
if (page.value !== newPage) pageInput.value = newPage.toString();
349353
page.value = newPage;
350354
});
351355

dev-demo/resources/apartment_buyers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
gender ENUM('m', 'f'),
2323
info LONGTEXT,
2424
contact_info JSON,
25-
language: CHAR(2),
25+
language CHAR(2),
2626
ideal_price DECIMAL(65, 2),
2727
ideal_space FLOAT(24),
2828
ideal_subway_distance FLOAT(53),

0 commit comments

Comments
 (0)