Skip to content

Commit

Permalink
fix(input): always call onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermerodz committed Feb 22, 2024
1 parent 44f08b7 commit 8dbc110
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/input-otp/src/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ export const OTPInput = React.forwardRef<HTMLInputElement, OTPInputProps>(
// Workarounds
const value = uncheckedValue ?? internalValue
const previousValue = usePrevious(value)
const onChange = uncheckedOnChange ?? setInternalValue
const onChange = (newValue: string) => {
// Check if input is controlled
if (uncheckedValue !== undefined) {
uncheckedOnChange?.(newValue)
} else {
setInternalValue(newValue)
uncheckedOnChange?.(newValue)
}
}
const regexp = pattern
? typeof pattern === 'string'
? new RegExp(pattern)
Expand Down
2 changes: 1 addition & 1 deletion packages/input-otp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type OTPInputProps = OverrideProps<
React.InputHTMLAttributes<HTMLInputElement>,
{
value?: string
onChange?: (...args: any[]) => unknown
onChange?: (newValue: string) => unknown

maxLength: number

Expand Down

0 comments on commit 8dbc110

Please sign in to comment.