Skip to content

Commit

Permalink
Fix #6573: add paste key (#6577)
Browse files Browse the repository at this point in the history
* Fix #6573: add paste key

* Update InputOtp.js

---------

Co-authored-by: Melloware <[email protected]>
  • Loading branch information
Rekl0w and melloware authored May 7, 2024
1 parent f35c8c2 commit 5dc01ee
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/lib/inputotp/InputOtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const InputOtp = React.memo(
};

const onInput = (event, index) => {
if (props.disabled || props.readOnly) {
return;
}

if (event.nativeEvent.inputType === 'insertFromPaste') {
return; // handled in onPaste
}
Expand All @@ -93,6 +97,10 @@ export const InputOtp = React.memo(
};

const onPaste = (event) => {
if (props.disabled || props.readOnly) {
return;
}

let paste = event.clipboardData.getData('text');

if (paste.length) {
Expand All @@ -117,6 +125,15 @@ export const InputOtp = React.memo(
};

const onKeydown = (event) => {
if (props.disabled || props.readOnly) {
return;
}

// special keys should be ignored, if it is CTRL+V is handled in onPaste
if (event.altKey || event.ctrlKey || event.metaKey) {
return;
}

switch (event.code) {
case 'ArrowLeft': {
moveToPrevInput(event);
Expand Down

0 comments on commit 5dc01ee

Please sign in to comment.