@@ -35,6 +35,7 @@ const props = withDefaults(defineProps<Props>(), {
35
35
isLastChild: false ,
36
36
placeholder: " " ,
37
37
isDisabled: false ,
38
+ value: " " ,
38
39
});
39
40
40
41
const emit = defineEmits <{
@@ -48,12 +49,19 @@ const emit = defineEmits<{
48
49
const model = ref (props .value || " " );
49
50
const input = ref <HTMLInputElement | null >(null ) as Ref <HTMLInputElement >;
50
51
51
- const handleOnChange = () => {
52
- model .value = model .value ;
53
- if (model .value .length > 1 ) {
54
- model .value = model .value .slice (0 , 1 );
52
+ const handleOnChange = (e : Event ) => {
53
+ const value = (e .target as HTMLInputElement ).value ;
54
+ if (value && value .trim ().length > 1 ) {
55
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
56
+ // @ts-ignore
57
+ // This is a workaround for dealing IOS does not fire onPaste event from sms auto-populate.
58
+ // The `:maxlength="isLastChild ? 1 : undefined"` on the input is also needed for this workaround.
59
+ e .clipboardData = {
60
+ getData : () => value .trim (),
61
+ };
62
+ return emit (" on-paste" , e as ClipboardEvent );
55
63
}
56
- return emit (" on-change" , model . value . toString () );
64
+ return emit (" on-change" , value );
57
65
};
58
66
59
67
const isCodeLetter = (charCode : number ) => charCode >= 65 && charCode <= 90 ;
@@ -134,9 +142,9 @@ onMounted(() => {
134
142
ref =" input"
135
143
min =" 0"
136
144
max =" 9"
137
- :maxlength =" 1 "
145
+ :maxlength =" isLastChild ? 1 : undefined "
138
146
pattern =" [0-9]"
139
- v-model =" model"
147
+ :value =" model"
140
148
:class =" [inputClasses, conditionalClass, { 'is-complete': model }]"
141
149
@input =" handleOnChange"
142
150
@keydown =" handleOnKeyDown"
0 commit comments