Skip to content

Commit 90b36c4

Browse files
committed
Fixed onCompleted trigger when placeholder is one character/digit
1 parent 0ea1362 commit 90b36c4

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export interface ReactInputVerificationCodeProps {
2323
const ReactInputVerificationCode = ({
2424
autoFocus = false,
2525
length = 4,
26-
onChange = () => {},
27-
onCompleted = () => {},
26+
onChange = () => { },
27+
onCompleted = () => { },
2828
placeholder = '·',
2929
value: pValue,
3030
dataCy = 'verification-code',
@@ -156,7 +156,7 @@ const ReactInputVerificationCode = ({
156156
const stringValue = value.join('');
157157
const isCompleted = stringValue.length === length;
158158

159-
if (isCompleted) onCompleted(stringValue);
159+
if (isCompleted && stringValue !== emptyValue.join('')) onCompleted(stringValue);
160160
onChange(stringValue);
161161
}, [value, length]);
162162

@@ -208,9 +208,8 @@ const ReactInputVerificationCode = ({
208208
ref={ref}
209209
role='button'
210210
tabIndex={0}
211-
className={`ReactInputVerificationCode__item ${
212-
value[i] !== placeholder ? 'is-filled' : ''
213-
} ${i === activeIndex ? 'is-active' : ''}`}
211+
className={`ReactInputVerificationCode__item ${value[i] !== placeholder ? 'is-filled' : ''
212+
} ${i === activeIndex ? 'is-active' : ''}`}
214213
onFocus={onItemFocus(i)}
215214
data-cy={`${dataCy}-${i}-item`}
216215
>

0 commit comments

Comments
 (0)