10
10
v-bind =" filteredProps"
11
11
:disabled =" readonly"
12
12
class =" flex-grow text-xs"
13
+ :step =" stepValue !== 'any' ? +stepValue : undefined"
13
14
@update:model-value =" updateLocalValue"
14
15
/>
15
16
<InputText
28
29
29
30
<script setup lang="ts">
30
31
import InputText from ' primevue/inputtext'
31
- import { computed , ref , watch } from ' vue'
32
+ import { computed } from ' vue'
32
33
33
34
import Slider from ' @/components/ui/slider/Slider.vue'
34
35
import { useNumberWidgetValue } from ' @/composables/graph/useWidgetValue'
@@ -42,7 +43,7 @@ import {
42
43
import { WidgetInputBaseClass } from ' ./layout'
43
44
import WidgetLayoutField from ' ./layout/WidgetLayoutField.vue'
44
45
45
- const props = defineProps <{
46
+ const { widget, modelValue, readonly } = defineProps <{
46
47
widget: SimplifiedWidget <number >
47
48
modelValue: number
48
49
readonly? : boolean
@@ -53,32 +54,28 @@ const emit = defineEmits<{
53
54
}>()
54
55
55
56
// Use the composable for consistent widget value handling
56
- const { localValue, onChange } = useNumberWidgetValue (
57
- props .widget ,
58
- props .modelValue ,
59
- emit
60
- )
57
+ const { localValue, onChange } = useNumberWidgetValue (widget , modelValue , emit )
61
58
62
59
const updateLocalValue = (newValue : number [] | undefined ): void => {
63
60
onChange (newValue ?? [])
64
61
}
65
62
66
63
const filteredProps = computed (() =>
67
- filterWidgetProps (props . widget .options , STANDARD_EXCLUDED_PROPS )
64
+ filterWidgetProps (widget .options , STANDARD_EXCLUDED_PROPS )
68
65
)
69
66
70
67
// Get the precision value for proper number formatting
71
68
const precision = computed (() => {
72
- const p = props . widget .options ?.precision
69
+ const p = widget .options ?.precision
73
70
// Treat negative or non-numeric precision as undefined
74
71
return typeof p === ' number' && p >= 0 ? p : undefined
75
72
})
76
73
77
74
// Calculate the step value based on precision or widget options
78
75
const stepValue = computed (() => {
79
76
// Use step2 (correct input spec value) instead of step (legacy 10x value)
80
- if (props . widget .options ?.step2 !== undefined ) {
81
- return String (props . widget .options .step2 )
77
+ if (widget .options ?.step2 !== undefined ) {
78
+ return String (widget .options .step2 )
82
79
}
83
80
// Otherwise, derive from precision
84
81
if (precision .value !== undefined ) {
@@ -119,12 +116,7 @@ const applyPrecision = (value: number): number => {
119
116
}
120
117
121
118
// Keep a separate display value for the input field
122
- const inputDisplayValue = ref (formatNumber (localValue .value ))
123
-
124
- // Update display value when localValue changes from external sources
125
- watch (localValue , (newValue ) => {
126
- inputDisplayValue .value = formatNumber (newValue )
127
- })
119
+ const inputDisplayValue = computed (() => formatNumber (localValue .value ))
128
120
129
121
const handleInputBlur = (event : Event ) => {
130
122
const target = event .target as HTMLInputElement
@@ -136,7 +128,7 @@ const handleInputBlur = (event: Event) => {
136
128
const roundedValue = applyPrecision (parsed )
137
129
onChange (roundedValue )
138
130
// Update display value with proper formatting
139
- inputDisplayValue .value = formatNumber ( roundedValue )
131
+ localValue .value = roundedValue
140
132
}
141
133
}
142
134
@@ -151,7 +143,7 @@ const handleInputKeydown = (event: KeyboardEvent) => {
151
143
const roundedValue = applyPrecision (parsed )
152
144
onChange (roundedValue )
153
145
// Update display value with proper formatting
154
- inputDisplayValue .value = formatNumber ( roundedValue )
146
+ localValue .value = roundedValue
155
147
}
156
148
}
157
149
}
0 commit comments