Skip to content

feat: add pointDown action #444

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@
};
}

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

Check warning on line 536 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L536

Added line #L536 was not covered by tests
// origin methods
originChildProps.onPointerDown?.(event, ...args);

Check warning on line 538 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L538

Added line #L538 was not covered by tests
}
}

Check warning on line 540 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

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 @@
};
}

// 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,
Expand All @@ -552,7 +567,6 @@
inPopupOrChild,
triggerOpen,
);

// ======================= Action: Hover ========================
const hoverToShow = showActions.has('hover');
const hoverToHide = hideActions.has('hover');
Expand Down Expand Up @@ -653,6 +667,7 @@
'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' | 'pointerDown';

export type AnimationType = string;

Expand Down
Loading