diff --git a/src/index.tsx b/src/index.tsx index d55c6b1d..b6e185db 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -523,6 +523,21 @@ export function generateTrigger( }; } + // ======================= Action: PointDown ======================== + const pointDownToShow = showActions.has('pointerDown'); + const pointDownToHide = hideActions.has('pointerDown'); + if (pointDownToShow || pointDownToHide) { + cloneProps.onPointerDown = (event: React.PointerEvent, ...args: any[]) => { + if (openRef.current && pointDownToHide) { + triggerOpen(false); // to hide + } else if (!openRef.current && pointDownToShow) { + setMousePosByEvent(event); + triggerOpen(true); + } + // origin methods + originChildProps.onPointerDown?.(event, ...args); + } + } // ======================= Action: Click ======================== if (clickToShow || clickToHide) { cloneProps.onClick = ( @@ -541,7 +556,7 @@ export function generateTrigger( }; } - // Click to hide is special action since click popup element should not hide + // Click/PointerDown to hide is special action since click popup element should not hide useWinClick( mergedOpen, clickToHide, @@ -552,7 +567,6 @@ export function generateTrigger( inPopupOrChild, triggerOpen, ); - // ======================= Action: Hover ======================== const hoverToShow = showActions.has('hover'); const hoverToHide = hideActions.has('hover'); @@ -653,6 +667,7 @@ export function generateTrigger( 'onMouseLeave', 'onFocus', 'onBlur', + 'onPointerDown', ]; passedEventList.forEach((eventName) => { diff --git a/src/interface.ts b/src/interface.ts index ddb27eec..8775800b 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -104,7 +104,7 @@ export type BuildInPlacements = Record; export type StretchType = string; -export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu'; +export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu' | 'pointerDown'; export type AnimationType = string;