Skip to content

Commit

Permalink
fix: fixes onClickOutside on iOS devices. fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitgrelard committed Aug 14, 2019
1 parent e886d62 commit 96d0756
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Effect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function Effect(
}
};

const onClick = (event: MouseEvent) => {
const onClick = (event: MouseEvent | TouchEvent) => {
if (event.defaultPrevented || event.target === lastEventTarget) {
return;
}
Expand Down Expand Up @@ -65,6 +65,7 @@ export function Effect(
}
document.addEventListener('keyup', onKeyPress);
document.addEventListener('click', onClick);
document.addEventListener('touchstart', onClick);
};

const onNodeDeactivation = () => {
Expand All @@ -74,12 +75,16 @@ export function Effect(
}
document.removeEventListener('keyup', onKeyPress);
document.removeEventListener('click', onClick);
document.removeEventListener('touchstart', onClick);
};

setLockProps({
onClick: (e: React.MouseEvent) => {
lastEventTarget = e.target
},
onTouchStart: (e: React.TouchEvent) => {
lastEventTarget = e.target
},
onActivation: onNodeActivation,
onDeactivation: onNodeDeactivation,
});
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as React from "react";
export interface LockProps {
onClick?(e: React.MouseEvent): void;

onTouchStart?(e: React.TouchEvent): void;

onActivation?(node: HTMLElement): void;

onDeactivation?(): void;
Expand Down Expand Up @@ -38,4 +40,4 @@ export interface ReactFocusOnSideProps extends ReactFocusOnProps {

export interface EffectProps extends CommonProps {
setLockProps(settings: LockProps): void;
}
}

0 comments on commit 96d0756

Please sign in to comment.