Skip to content

Commit b251836

Browse files
committed
update
1 parent a05aaaf commit b251836

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/Popup/Arrow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
44

55
export interface ArrowProps {
66
prefixCls: string;
7-
align: AlignType;
7+
align?: AlignType;
88
arrow: ArrowTypeOuter;
99
arrowPos: ArrowPos;
1010
}

src/hooks/useOffsetStyle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export default function useOffsetStyle(
2828
const { points } = align;
2929
const dynamicInset =
3030
align.dynamicInset || (align as any)._experimental?.dynamicInset;
31-
const alignRight = dynamicInset && points[0][1] === 'r';
32-
const alignBottom = dynamicInset && points[0][0] === 'b';
31+
const alignRight = dynamicInset && points?.[0][1] === 'r';
32+
const alignBottom = dynamicInset && points?.[0][0] === 'b';
3333

3434
if (alignRight) {
3535
offsetStyle.right = offsetR;

src/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
useLayoutEffect,
1414
} from '@rc-component/util';
1515
import * as React from 'react';
16-
import Popup, { type MobileConfig } from './Popup';
16+
import Popup from './Popup';
17+
import type { MobileConfig } from './Popup';
1718
import type { TriggerContextProps } from './context';
1819
import TriggerContext, { UniqueContext } from './context';
1920
import useAction from './hooks/useAction';
@@ -24,15 +25,14 @@ import useWinClick from './hooks/useWinClick';
2425
import type { PortalProps } from '@rc-component/portal';
2526
import { isPointInSafeHoverArea } from './util/safeHover';
2627
import type { SafeHoverPoint } from './util/safeHover';
27-
2828
import type {
2929
ActionType,
3030
AlignType,
3131
ArrowPos,
3232
ArrowTypeOuter,
3333
BuildInPlacements,
3434
} from './interface';
35-
import { getAlignPopupClassName } from './util';
35+
import { clamp, getAlignPopupClassName } from './util';
3636

3737
export type {
3838
ActionType,
@@ -480,10 +480,8 @@ export function generateTrigger(
480480
popupEle.getBoundingClientRect(),
481481
);
482482

483-
const refreshDelay = Math.max(
484-
1000 / 60,
485-
Math.min(mouseLeaveDelay * 1000, 1000),
486-
);
483+
// Between 1 frame and 1 second
484+
const refreshDelay = clamp(mouseLeaveDelay * 1000, 1000 / 60, 1000);
487485

488486
const scheduleRefresh = () => {
489487
const safeHover = safeHoverRef.current;

src/util.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ export function collectScroller(ele: HTMLElement) {
5252

5353
while (current) {
5454
const { overflowX, overflowY, overflow } =
55-
getWin(current).getComputedStyle(current);
56-
if ([overflowX, overflowY, overflow].some((o) => scrollStyle.includes(o))) {
55+
getWin(current)?.getComputedStyle(current) || {};
56+
57+
if (
58+
[overflowX, overflowY, overflow].some((o) => o && scrollStyle.includes(o))
59+
) {
5760
scrollerList.push(current);
5861
}
5962

@@ -67,10 +70,17 @@ export function toNum(num: number, defaultValue = 1) {
6770
return Number.isNaN(num) ? defaultValue : num;
6871
}
6972

70-
function getPxValue(val: string) {
71-
return toNum(parseFloat(val), 0);
73+
function getPxValue(val?: string) {
74+
if (!val) {
75+
return 0;
76+
}
77+
return toNum(Number.parseFloat(val), 0);
7278
}
7379

80+
export const clamp = (num: number, min: number, max: number) => {
81+
return Math.min(Math.max(num, min), max);
82+
};
83+
7484
export interface VisibleArea {
7585
left: number;
7686
top: number;
@@ -119,7 +129,7 @@ export function getVisibleArea(
119129
borderBottomWidth,
120130
borderLeftWidth,
121131
borderRightWidth,
122-
} = getWin(ele).getComputedStyle(ele);
132+
} = getWin(ele)?.getComputedStyle(ele) || {};
123133

124134
const eleRect = ele.getBoundingClientRect();
125135
const {

0 commit comments

Comments
 (0)