Skip to content

Commit

Permalink
fix(kit): maskitoCaretGuard doesn't work after focus on <select /> (
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov authored Aug 30, 2023
1 parent ff862aa commit 9f456da
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions projects/kit/src/lib/plugins/caret-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function maskitoCaretGuard(
const document = element.ownerDocument;
let isPointerDown = 0;
const onPointerDown = (): number => isPointerDown++;
const onPointerUp = (): number => isPointerDown--;
const onPointerUp = (): void => {
isPointerDown = Math.max(--isPointerDown, 0);
};

const listener = (): void => {
if (getFocused(document) !== element) {
Expand All @@ -39,7 +41,7 @@ export function maskitoCaretGuard(
};

document.addEventListener('selectionchange', listener, {passive: true});
document.addEventListener('mousedown', onPointerDown, {passive: true});
element.addEventListener('mousedown', onPointerDown, {passive: true});
document.addEventListener('mouseup', onPointerUp, {passive: true});

return () => {
Expand Down

0 comments on commit 9f456da

Please sign in to comment.