Skip to content

Commit

Permalink
fix(InputMask): Paste at Cursor Selection (primefaces#5286)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Triggs125 and melloware authored Nov 13, 2023
1 parent 9c64833 commit 02f78ab
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/lib/inputmask/InputMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 02f78ab

Please sign in to comment.