Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): always call onChange #17

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading