Skip to content

Commit d35ce27

Browse files
committed
2 parents 92f5189 + a0f72f7 commit d35ce27

File tree

3 files changed

+54
-86
lines changed

3 files changed

+54
-86
lines changed

src/Popup/Arrow.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,32 @@ export default function Arrow(props: ArrowProps) {
2222
position: 'absolute',
2323
};
2424

25-
const popupPoints = align.points[0];
26-
const targetPoints = align.points[1];
27-
const popupTB = popupPoints[0];
28-
const popupLR = popupPoints[1];
29-
const targetTB = targetPoints[0];
30-
const targetLR = targetPoints[1];
31-
32-
// Top & Bottom
33-
if (popupTB === targetTB || !['t', 'b'].includes(popupTB)) {
34-
alignStyle.top = arrowY;
35-
} else if (popupTB === 't') {
36-
alignStyle.top = 0;
37-
} else {
38-
alignStyle.bottom = 0;
39-
}
40-
41-
// Left & Right
42-
if (popupLR === targetLR || !['l', 'r'].includes(popupLR)) {
43-
alignStyle.left = arrowX;
44-
} else if (popupLR === 'l') {
45-
alignStyle.left = 0;
46-
} else {
47-
alignStyle.right = 0;
25+
// Skip if no need to align
26+
if (align.autoArrow !== false) {
27+
const popupPoints = align.points[0];
28+
const targetPoints = align.points[1];
29+
const popupTB = popupPoints[0];
30+
const popupLR = popupPoints[1];
31+
const targetTB = targetPoints[0];
32+
const targetLR = targetPoints[1];
33+
34+
// Top & Bottom
35+
if (popupTB === targetTB || !['t', 'b'].includes(popupTB)) {
36+
alignStyle.top = arrowY;
37+
} else if (popupTB === 't') {
38+
alignStyle.top = 0;
39+
} else {
40+
alignStyle.bottom = 0;
41+
}
42+
43+
// Left & Right
44+
if (popupLR === targetLR || !['l', 'r'].includes(popupLR)) {
45+
alignStyle.left = arrowX;
46+
} else if (popupLR === 'l') {
47+
alignStyle.left = 0;
48+
} else {
49+
alignStyle.right = 0;
50+
}
4851
}
4952

5053
return (

src/interface.ts

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,6 @@ export type Placement =
1414
| 'rightTop'
1515
| 'rightBottom';
1616

17-
export interface TriggerProps {
18-
children: React.ReactElement;
19-
action?: ActionType | ActionType[];
20-
showAction?: ActionType[];
21-
hideAction?: ActionType[];
22-
getPopupClassNameFromAlign?: (align: AlignType) => string;
23-
onPopupVisibleChange?: (visible: boolean) => void;
24-
onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
25-
afterPopupVisibleChange?: (visible: boolean) => void;
26-
popup: React.ReactNode | (() => React.ReactNode);
27-
popupStyle?: React.CSSProperties;
28-
prefixCls?: string;
29-
popupClassName?: string;
30-
className?: string;
31-
popupPlacement?: string;
32-
builtinPlacements?: BuildInPlacements;
33-
mouseEnterDelay?: number;
34-
mouseLeaveDelay?: number;
35-
zIndex?: number;
36-
focusDelay?: number;
37-
blurDelay?: number;
38-
getPopupContainer?: (node: HTMLElement) => HTMLElement;
39-
getDocument?: (element?: HTMLElement) => HTMLDocument;
40-
forceRender?: boolean;
41-
destroyPopupOnHide?: boolean;
42-
mask?: boolean;
43-
maskClosable?: boolean;
44-
onPopupAlign?: (element: HTMLElement, align: AlignType) => void;
45-
popupAlign?: AlignType;
46-
popupVisible?: boolean;
47-
defaultPopupVisible?: boolean;
48-
autoDestroy?: boolean;
49-
50-
stretch?: string;
51-
alignPoint?: boolean; // Maybe we can support user pass position in the future
52-
53-
/** Set popup motion. You can ref `rc-motion` for more info. */
54-
popupMotion?: CSSMotionProps;
55-
/** Set mask motion. You can ref `rc-motion` for more info. */
56-
maskMotion?: CSSMotionProps;
57-
58-
/** @deprecated Please us `popupMotion` instead. */
59-
popupTransitionName?: TransitionNameType;
60-
/** @deprecated Please us `popupMotion` instead. */
61-
popupAnimation?: AnimationType;
62-
/** @deprecated Please us `maskMotion` instead. */
63-
maskTransitionName?: TransitionNameType;
64-
/** @deprecated Please us `maskMotion` instead. */
65-
maskAnimation?: string;
66-
67-
/**
68-
* @private Get trigger DOM node.
69-
* Used for some component is function component which can not access by `findDOMNode`
70-
*/
71-
getTriggerDOMNode?: (node: React.ReactInstance) => HTMLElement;
72-
73-
// ========================== Mobile ==========================
74-
/** @private Bump fixed position at bottom in mobile.
75-
* This is internal usage currently, do not use in your prod */
76-
mobile?: MobileConfig;
77-
}
78-
7917
export type AlignPointTopBottom = 't' | 'b' | 'c';
8018
export type AlignPointLeftRight = 'l' | 'r' | 'c';
8119

@@ -108,6 +46,8 @@ export interface AlignType {
10846
shiftX?: boolean | number;
10947
shiftY?: boolean | number;
11048
};
49+
/** Auto adjust arrow position */
50+
autoArrow?: boolean;
11151
/**
11252
* Whether use css right instead of left to position
11353
*/

tests/arrow.test.jsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ describe('Trigger.Arrow', () => {
8080

8181
await awaitFakeTimer();
8282

83-
console.log(document.body.innerHTML);
8483
expect(document.querySelector('.rc-trigger-popup-arrow')).toHaveStyle(
8584
style,
8685
);
@@ -130,5 +129,31 @@ describe('Trigger.Arrow', () => {
130129
left: 0,
131130
},
132131
);
132+
133+
it('not aligned', async () => {
134+
render(
135+
<Trigger
136+
popupVisible
137+
popupAlign={{
138+
points: ['cl', 'cr'],
139+
autoArrow: false,
140+
}}
141+
popup={<strong>trigger</strong>}
142+
arrow
143+
>
144+
<div />
145+
</Trigger>,
146+
);
147+
148+
await awaitFakeTimer();
149+
150+
// Not have other align style
151+
const { style } = document.querySelector('.rc-trigger-popup-arrow')
152+
expect(style.position).toBeTruthy();
153+
expect(style.left).toBeFalsy();
154+
expect(style.right).toBeFalsy();
155+
expect(style.top).toBeFalsy();
156+
expect(style.bottom).toBeFalsy();
157+
});
133158
});
134159
});

0 commit comments

Comments
 (0)