98
98
</template >
99
99
100
100
<script setup>
101
- import { computed , ref , useSlots } from ' vue' ;
101
+ import { computed , ref , useSlots , nextTick } from ' vue' ;
102
102
import Add16 from ' @carbon/icons-vue/es/add/16' ;
103
103
import Subtract16 from ' @carbon/icons-vue/es/subtract/16' ;
104
104
import WarningFilled16 from ' @carbon/icons-vue/es/warning--filled/16' ;
@@ -114,7 +114,7 @@ const props = defineProps({
114
114
disabled: Boolean ,
115
115
modelValue: {
116
116
type: [String , Number ],
117
- default: ' ' ,
117
+ default: undefined ,
118
118
},
119
119
formItem: {
120
120
type: Boolean ,
@@ -190,18 +190,23 @@ const modelValueType = typeof props.modelValue;
190
190
const valuesToNaN = [' ' , null , undefined ];
191
191
192
192
const formatInputValueType = value => {
193
- if (modelValueType === ' string' ) return value .toString ();
193
+ if (modelValueType === ' string' ) return Number ( value) .toString ();
194
194
// According to Vue2 component if there is no value NaN is emitted
195
195
return valuesToNaN .includes (value) ? NaN : Number (value);
196
196
};
197
197
198
+ const displayValue = ref (props .modelValue || props .min );
198
199
const internalValue = computed ({
199
200
get () {
200
- return props .modelValue ;
201
+ return props .modelValue || displayValue . value ;
201
202
},
202
203
set (value ) {
203
- const valueFormatted = formatInputValueType (value);
204
- onInput (valueFormatted);
204
+ displayValue .value = formatInputValueType (value);
205
+ if (Number .isNaN (displayValue .value ) || displayValue .value === ' NaN' ) {
206
+ displayValue .value = 0 ;
207
+ nextTick (() => (displayValue .value = NaN ));
208
+ }
209
+ onInput (displayValue .value );
205
210
},
206
211
});
207
212
0 commit comments