Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pointDown action #444

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@ export function generateTrigger(
};
}

// ======================= Action: PointDown ========================
const pointDownToShow = showActions.has('pointDown');
const pointDownToHide = hideActions.has('pointDown');
if (pointDownToShow || pointDownToHide) {
cloneProps.onPointDown = (event: React.PointerEvent<HTMLElement>, ...args: any[]) => {
if (openRef.current && pointDownToHide) {
triggerOpen(false); // to hide
} else if (!openRef.current && pointDownToShow) {
setMousePosByEvent(event);
triggerOpen(true);
}
// origin methods
originChildProps.onPointDown?.(event, ...args);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码更改看起来不错!

新添加的代码正确地实现了处理 onPointDown 事件的功能。该逻辑检查是否启用了在指针按下事件上显示或隐藏组件的操作。如果是,它会为 cloneProps.onPointDown 分配一个新的事件处理程序。此处理程序根据当前状态和指定的操作来确定是触发打开还是关闭组件。

提醒:为新代码路径添加测试。

静态分析工具指出,添加的第 538 行和第 540 行未被测试覆盖。

您希望我生成测试代码还是开一个 GitHub issue 来跟踪此任务?

Tools
GitHub Check: codecov/patch

[warning] 538-538: src/index.tsx#L538
Added line #L538 was not covered by tests


[warning] 540-540: src/index.tsx#L540
Added line #L540 was not covered by tests

// ======================= Action: Click ========================
if (clickToShow || clickToHide) {
cloneProps.onClick = (
Expand All @@ -541,7 +556,7 @@ export function generateTrigger(
};
}

// Click to hide is special action since click popup element should not hide
// Click/PointDown to hide is special action since click popup element should not hide
useWinClick(
mergedOpen,
clickToHide,
Expand All @@ -552,7 +567,7 @@ export function generateTrigger(
inPopupOrChild,
triggerOpen,
);

afc163 marked this conversation as resolved.
Show resolved Hide resolved
// ======================= Action: Hover ========================
const hoverToShow = showActions.has('hover');
const hoverToHide = hideActions.has('hover');
Expand Down Expand Up @@ -653,6 +668,7 @@ export function generateTrigger(
'onMouseLeave',
'onFocus',
'onBlur',
'onPointerDown',
];

passedEventList.forEach((eventName) => {
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export type BuildInPlacements = Record<string, AlignType>;

export type StretchType = string;

export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
export type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu' | 'pointDown';

export type AnimationType = string;

Expand Down