File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,22 @@ export default function App() {
80
80
<td>console.log</td>
81
81
<td>Returns OTP code typed in inputs.</td>
82
82
</tr >
83
+ <tr >
84
+ <td>onPaste</td>
85
+ <td>function</td>
86
+ <td>false</td>
87
+ <td>none</td>
88
+ <td>Provide a custom onPaste event handler scoped to the OTP inputs container. Executes when content is pasted into any OTP field.
89
+ </br></br>
90
+ Example:
91
+ <pre>
92
+ const handlePaste: React.ClipboardEventHandler<HTMLDivElement > = (event) => {
93
+ const data = event.clipboardData.getData('text');
94
+ console.log(data)
95
+ };</pre >
96
+
97
+ </td >
98
+ </tr >
83
99
<tr >
84
100
<td>value</td>
85
101
<td>string / number</td>
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ interface OTPInputProps {
32
32
numInputs ?: number ;
33
33
/** Callback to be called when the OTP value changes */
34
34
onChange : ( otp : string ) => void ;
35
+ /** Callback to be called when pasting content into the component */
36
+ onPaste ?: ( event : React . ClipboardEvent < HTMLDivElement > ) => void ;
35
37
/** Function to render the input */
36
38
renderInput : ( inputProps : InputProps , index : number ) => React . ReactNode ;
37
39
/** Whether the first input should be auto focused */
@@ -54,6 +56,7 @@ const OTPInput = ({
54
56
value = '' ,
55
57
numInputs = 4 ,
56
58
onChange,
59
+ onPaste,
57
60
renderInput,
58
61
shouldAutoFocus = false ,
59
62
inputType = 'text' ,
@@ -217,6 +220,7 @@ const OTPInput = ({
217
220
< div
218
221
style = { Object . assign ( { display : 'flex' , alignItems : 'center' } , isStyleObject ( containerStyle ) && containerStyle ) }
219
222
className = { typeof containerStyle === 'string' ? containerStyle : undefined }
223
+ onPaste = { onPaste }
220
224
>
221
225
{ Array . from ( { length : numInputs } , ( _ , index ) => index ) . map ( ( index ) => (
222
226
< React . Fragment key = { index } >
You can’t perform that action at this time.
0 commit comments