fix: select text on focus

This commit is contained in:
Shariq Ansari 2025-05-14 13:34:21 +05:30
parent 32f3aaf38f
commit 8f79427720
2 changed files with 18 additions and 6 deletions

View File

@ -1,14 +1,15 @@
<template>
<FormControl
<TextInput
ref="inputRef"
:value="displayValue"
@focus="isFocused = true"
@focus="handleFocus"
@blur="isFocused = false"
v-bind="$attrs"
/>
</template>
<script setup>
import { FormControl } from 'frappe-ui'
import { ref, computed } from 'vue'
import { TextInput } from 'frappe-ui'
import { ref, computed, nextTick } from 'vue'
const props = defineProps({
value: {
@ -22,8 +23,19 @@ const props = defineProps({
})
const isFocused = ref(false)
const inputRef = ref(null)
function handleFocus() {
isFocused.value = true
nextTick(() => {
if (inputRef.value) {
inputRef.value.el?.select()
}
})
}
const displayValue = computed(() => {
return isFocused.value ? props.value : props.formattedValue
return isFocused.value ? props.value : props.formattedValue || props.value
})
</script>

View File

@ -206,7 +206,7 @@
:options="field.options"
@change="(e) => fieldChange(e.target.value, field, row)"
/>
<FormControl
<FormattedInput
v-else-if="field.fieldtype === 'Int'"
class="[&_input]:text-right"
type="text"