Skip to content

Commit 1be7cd6

Browse files
committed
feat: ✨ add pointerDown action
1 parent 7edea91 commit 1be7cd6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,21 @@ export function generateTrigger(
523523
};
524524
}
525525

526+
// ======================= Action: PointDown ========================
527+
const pointDownToShow = showActions.has('pointDown');
528+
const pointDownToHide = hideActions.has('pointDown');
529+
if (pointDownToShow || pointDownToHide) {
530+
cloneProps.onPointDown = (event: React.PointerEvent<HTMLElement>, ...args: any[]) => {
531+
if (openRef.current && pointDownToHide) {
532+
triggerOpen(false); // to hide
533+
} else if (!openRef.current && pointDownToShow) {
534+
setMousePosByEvent(event);
535+
triggerOpen(true);
536+
}
537+
// origin methods
538+
originChildProps.onPointDown?.(event, ...args);
539+
}
540+
}
526541
// ======================= Action: Click ========================
527542
if (clickToShow || clickToHide) {
528543
cloneProps.onClick = (
@@ -541,7 +556,7 @@ export function generateTrigger(
541556
};
542557
}
543558

544-
// Click to hide is special action since click popup element should not hide
559+
// Click/PointDown to hide is special action since click popup element should not hide
545560
useWinClick(
546561
mergedOpen,
547562
clickToHide,
@@ -552,7 +567,7 @@ export function generateTrigger(
552567
inPopupOrChild,
553568
triggerOpen,
554569
);
555-
570+
556571
// ======================= Action: Hover ========================
557572
const hoverToShow = showActions.has('hover');
558573
const hoverToHide = hideActions.has('hover');

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type BuildInPlacements = Record<string, AlignType>;
104104

105105
export type StretchType = string;
106106

107-
export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
107+
export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu' | 'pointDown';
108108

109109
export type AnimationType = string;
110110

0 commit comments

Comments
 (0)