Skip to content

Commit 8dbc110

Browse files
committed
fix(input): always call onChange
1 parent 44f08b7 commit 8dbc110

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/input-otp/src/input.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ export const OTPInput = React.forwardRef<HTMLInputElement, OTPInputProps>(
3030
// Workarounds
3131
const value = uncheckedValue ?? internalValue
3232
const previousValue = usePrevious(value)
33-
const onChange = uncheckedOnChange ?? setInternalValue
33+
const onChange = (newValue: string) => {
34+
// Check if input is controlled
35+
if (uncheckedValue !== undefined) {
36+
uncheckedOnChange?.(newValue)
37+
} else {
38+
setInternalValue(newValue)
39+
uncheckedOnChange?.(newValue)
40+
}
41+
}
3442
const regexp = pattern
3543
? typeof pattern === 'string'
3644
? new RegExp(pattern)

packages/input-otp/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type OTPInputProps = OverrideProps<
88
React.InputHTMLAttributes<HTMLInputElement>,
99
{
1010
value?: string
11-
onChange?: (...args: any[]) => unknown
11+
onChange?: (newValue: string) => unknown
1212

1313
maxLength: number
1414

0 commit comments

Comments
 (0)