From 02f78ab71f841742465bdeff27dc0ba0f8d4b325 Mon Sep 17 00:00:00 2001 From: Triggs Date: Mon, 13 Nov 2023 09:54:12 -0500 Subject: [PATCH] fix(InputMask): Paste at Cursor Selection (#5286) * fix(InputMask): Paste at Cursor Selection The input mask component currently pastes contents at the first empty value position instead of the cursor selection. Providing an undefined position to the caret function *mostly* fixes this issue because after the paste happens, the cursor is returned to the last empty value position instead of at the end of the newly pasted value. * Update duplicate code * Remove whitespace * Update InputMask.js * Update InputMask.js --------- Co-authored-by: Melloware --- components/lib/inputmask/InputMask.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/lib/inputmask/InputMask.js b/components/lib/inputmask/InputMask.js index 04568f0086..2490ebca5b 100644 --- a/components/lib/inputmask/InputMask.js +++ b/components/lib/inputmask/InputMask.js @@ -411,14 +411,17 @@ export const InputMask = React.memo( androidChrome.current ? handleAndroidInput(event) : handleInputChange(event); }; - const handleInputChange = (e) => { + const handleInputChange = (e, isOnPaste = false) => { if (props.readOnly) { return; } - let pos = checkVal(true); + if (!isOnPaste) { + let pos = checkVal(true); + + caret(pos); + } - caret(pos); updateModel(e); if (props.onComplete && isCompleted()) { @@ -607,7 +610,7 @@ export const InputMask = React.memo( onKeyDown={onKeyDown} onKeyPress={onKeyPress} onInput={onInput} - onPaste={handleInputChange} + onPaste={(e) => handleInputChange(e, true)} required={props.required} tooltip={props.tooltip} tooltipOptions={props.tooltipOptions}