From 8dc38912c92011289294ba102480bf19fbcac054 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Mon, 27 Jan 2025 00:05:34 +0800 Subject: [PATCH] select amount value when click the amount text box and the amount value is zero (#36, #45) --- src/components/desktop/AmountInput.vue | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/desktop/AmountInput.vue b/src/components/desktop/AmountInput.vue index cde42e14..85135df7 100644 --- a/src/components/desktop/AmountInput.vue +++ b/src/components/desktop/AmountInput.vue @@ -5,7 +5,7 @@ :label="label" :placeholder="placeholder" :persistent-placeholder="!!persistentPlaceholder" :rules="enableRules ? rules : []" v-model="currentValue" v-if="!hide" - @keydown="onKeyUpDown" @keyup="onKeyUpDown" @paste="onPaste"> + @keydown="onKeyUpDown" @keyup="onKeyUpDown" @paste="onPaste" @click="onClick"> @@ -19,7 +19,7 @@ :label="label" :placeholder="placeholder" :persistent-placeholder="!!persistentPlaceholder" :rules="enableRules ? rules : []" v-model="currentValue" v-if="hide" - @keydown="onKeyUpDown" @keyup="onKeyUpDown" @paste="onPaste"> + @keydown="onKeyUpDown" @keyup="onKeyUpDown" @paste="onPaste" @click="onClick"> @@ -90,6 +90,7 @@ const rules = [ ]; const currentValue = ref(getFormattedValue(props.modelValue)); + const prependText = computed(() => { if (!props.currency || !props.showCurrency) { return ''; @@ -261,6 +262,13 @@ function onPaste(e: ClipboardEvent): void { e.preventDefault(); } +function onClick(e: MouseEvent): void { + if (!props.disabled && !props.readonly && props.modelValue === 0) { + const input = e.target as HTMLInputElement; + input?.select(); + } +} + function getValidFormattedValue(value: number, textualValue: string, hasDecimalSeparator: boolean): string { let maxLength = TRANSACTION_MAX_AMOUNT.toString().length;