Skip to content

Commit

Permalink
Fix #5747: InputMask caret() null checking (#5764)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jan 13, 2024
1 parent b913fab commit 2f1ffdc
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions components/lib/inputmask/InputMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const InputMask = React.memo(
let inputEl = elementRef.current;

if (!inputEl || !inputEl.offsetParent || inputEl !== document.activeElement) {
return;
return null;
}

if (typeof first === 'number') {
Expand All @@ -57,9 +57,9 @@ export const InputMask = React.memo(
begin = 0 - range.duplicate().moveStart('character', -100000);
end = begin + range.text.length;
}

return { begin: begin, end: end };
}

return { begin: begin, end: end };
};

const isCompleted = () => {
Expand Down Expand Up @@ -145,6 +145,10 @@ export const InputMask = React.memo(
let curVal = elementRef.current.value;
let pos = caret();

if (!pos) {
return;
}

if (oldVal.current.length && oldVal.current.length > curVal.length) {
// a deletion or backspace happened
checkVal(true);
Expand Down Expand Up @@ -203,6 +207,11 @@ export const InputMask = React.memo(
//backspace, delete, and escape get special treatment
if (k === 8 || k === 46 || (DomHandler.isIOS() && k === 127)) {
pos = caret();

if (!pos) {
return;
}

begin = pos.begin;
end = pos.end;

Expand Down Expand Up @@ -234,8 +243,13 @@ export const InputMask = React.memo(
return;
}

const pos = caret();

if (!pos) {
return;
}

let k = e.which || e.keyCode,
pos = caret(),
p,
c,
next,
Expand Down

0 comments on commit 2f1ffdc

Please sign in to comment.