@@ -27,11 +27,11 @@ export default defineComponent({
2727 props ,
2828 setup(props , { emit }) {
2929 const { length, bindInputOtpItem } = useInputOtpItems ()
30- const activeInput = ref ( )
30+ const activeInput = ref < number >( - 1 )
3131
3232 const model = computed ({
3333 get : () => props .modelValue ,
34- set : (value ) => {
34+ set : (value : string ) => {
3535 call (props .onChange , value )
3636 call (props [' onUpdate:modelValue' ], value )
3737 validateWithTrigger (' onChange' )
@@ -44,14 +44,14 @@ export default defineComponent({
4444 parentModel: model ,
4545 activeInput ,
4646 length ,
47- disabled: ref ( props .disabled ),
48- readonly: ref ( props .readonly ),
49- variant: ref ( props .variant ),
50- size: ref ( props .size ),
51- textColor: ref ( props .textColor ),
52- focusColor: ref ( props .focusColor ),
53- blurColor: ref ( props .blurColor ),
54- autofocus: ref ( props .autofocus ),
47+ disabled: computed (() => props .disabled ),
48+ readonly: computed (() => props .readonly ),
49+ variant: computed (() => props .variant ),
50+ size: computed (() => props .size ),
51+ textColor: computed (() => props .textColor ),
52+ focusColor: computed (() => props .focusColor ),
53+ blurColor: computed (() => props .blurColor ),
54+ autofocus: computed (() => props .autofocus ),
5555 onItemChange ,
5656 onItemFocus ,
5757 onItemBlur ,
@@ -75,14 +75,15 @@ export default defineComponent({
7575 function onItemChange(index : number , value ? : string ) {
7676 if (value == null ) {
7777 activeInput .value = index
78+ return
79+ }
80+
81+ const currentValue = model .value || ' '
82+ if (index < length .value ) {
83+ activeInput .value = value ? index + 1 : index - 1
84+ emit (' update:modelValue' , currentValue .slice (0 , index ) + value + currentValue .slice (index + 1 ))
7885 } else {
79- const currentValue = model .value || ' '
80- if (index < length .value ) {
81- activeInput .value = value ? index + 1 : index - 1
82- emit (' update:modelValue' , currentValue .slice (0 , index ) + value + currentValue .slice (index + 1 ))
83- } else {
84- emit (' update:modelValue' , currentValue + value )
85- }
86+ emit (' update:modelValue' , currentValue + value )
8687 }
8788 }
8889
0 commit comments