Skip to content

Commit

Permalink
feat(input): add pasteTransformer prop
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermerodz committed Nov 1, 2024
1 parent 948354e commit 64c6f80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/input-otp/src/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const OTPInput = React.forwardRef<HTMLInputElement, OTPInputProps>(
inputMode = 'numeric',
onComplete,
pushPasswordManagerStrategy = 'increase-width',
pasteTransformer,
containerClassName,
noScriptCSSFallback = NOSCRIPT_CSS_FALLBACK,

Expand Down Expand Up @@ -311,11 +312,15 @@ export const OTPInput = React.forwardRef<HTMLInputElement, OTPInputProps>(
const _pasteListener = React.useCallback(
(e: React.ClipboardEvent<HTMLInputElement>) => {
const input = inputRef.current
if (!initialLoadRef.current.isIOS || !e.clipboardData || !input) {
if (!pasteTransformer && (!initialLoadRef.current.isIOS || !e.clipboardData || !input)) {
return
}

const content = e.clipboardData.getData('text/plain')

const _content = e.clipboardData.getData('text/plain')
const content = pasteTransformer
? pasteTransformer(_content)
: _content
console.log({_content,content})
e.preventDefault()

const start = inputRef.current?.selectionStart
Expand Down
1 change: 1 addition & 0 deletions packages/input-otp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type OTPInputBaseProps = OverrideProps<

onComplete?: (...args: any[]) => unknown
pushPasswordManagerStrategy?: 'increase-width' | 'none'
pasteTransformer?: (pasted: string) => string

containerClassName?: string

Expand Down

0 comments on commit 64c6f80

Please sign in to comment.