@rc-component/trigger 1.3.5 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/hooks/useAlign.js +20 -9
- package/es/index.js +5 -2
- package/es/interface.d.ts +6 -0
- package/lib/hooks/useAlign.js +20 -9
- package/lib/index.js +5 -2
- package/lib/interface.d.ts +6 -0
- package/package.json +1 -1
package/es/hooks/useAlign.js
CHANGED
|
@@ -84,6 +84,9 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
84
84
|
var doc = popupElement.ownerDocument;
|
|
85
85
|
var win = getWin(popupElement);
|
|
86
86
|
|
|
87
|
+
// Placement
|
|
88
|
+
var placementInfo = builtinPlacements[placement] || popupAlign || {};
|
|
89
|
+
|
|
87
90
|
// Reset first
|
|
88
91
|
popupElement.style.left = '0';
|
|
89
92
|
popupElement.style.top = '0';
|
|
@@ -112,12 +115,23 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
112
115
|
height = _win$getComputedStyle.height;
|
|
113
116
|
var _doc$documentElement = doc.documentElement,
|
|
114
117
|
clientWidth = _doc$documentElement.clientWidth,
|
|
115
|
-
clientHeight = _doc$documentElement.clientHeight
|
|
118
|
+
clientHeight = _doc$documentElement.clientHeight,
|
|
119
|
+
scrollWidth = _doc$documentElement.scrollWidth,
|
|
120
|
+
scrollHeight = _doc$documentElement.scrollHeight,
|
|
121
|
+
scrollTop = _doc$documentElement.scrollTop,
|
|
122
|
+
scrollLeft = _doc$documentElement.scrollLeft;
|
|
116
123
|
var popupHeight = popupRect.height;
|
|
117
124
|
var popupWidth = popupRect.width;
|
|
118
125
|
|
|
119
126
|
// Get bounding of visible area
|
|
120
|
-
var visibleArea =
|
|
127
|
+
var visibleArea = placementInfo.htmlRegion === 'scroll' ?
|
|
128
|
+
// Scroll region should take scrollLeft & scrollTop into account
|
|
129
|
+
{
|
|
130
|
+
left: -scrollLeft,
|
|
131
|
+
top: -scrollTop,
|
|
132
|
+
right: scrollWidth - scrollLeft,
|
|
133
|
+
bottom: scrollHeight - scrollTop
|
|
134
|
+
} : {
|
|
121
135
|
left: 0,
|
|
122
136
|
top: 0,
|
|
123
137
|
right: clientWidth,
|
|
@@ -131,10 +145,10 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
131
145
|
eleInnerWidth = ele.clientWidth;
|
|
132
146
|
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
133
147
|
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
134
|
-
var
|
|
135
|
-
var
|
|
136
|
-
var eleRight = eleRect.x + eleRect.width -
|
|
137
|
-
var eleBottom = eleRect.y + eleRect.height -
|
|
148
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
149
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
150
|
+
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
151
|
+
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
138
152
|
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
139
153
|
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
140
154
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
@@ -149,9 +163,6 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
149
163
|
var _scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
150
164
|
var _scaleY = toNum(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
|
|
151
165
|
|
|
152
|
-
// Placement
|
|
153
|
-
var placementInfo = popupAlign || builtinPlacements[placement] || {};
|
|
154
|
-
|
|
155
166
|
// Offset
|
|
156
167
|
var offset = placementInfo.offset,
|
|
157
168
|
targetOffset = placementInfo.targetOffset;
|
package/es/index.js
CHANGED
|
@@ -201,9 +201,12 @@ export function generateTrigger() {
|
|
|
201
201
|
useLayoutEffect(function () {
|
|
202
202
|
triggerAlign();
|
|
203
203
|
}, [mousePos]);
|
|
204
|
+
|
|
205
|
+
// When no builtinPlacements and popupAlign changed
|
|
204
206
|
useLayoutEffect(function () {
|
|
205
|
-
if (!
|
|
206
|
-
|
|
207
|
+
if (mergedOpen && !(builtinPlacements !== null && builtinPlacements !== void 0 && builtinPlacements[popupPlacement])) {
|
|
208
|
+
triggerAlign();
|
|
209
|
+
}
|
|
207
210
|
}, [JSON.stringify(popupAlign)]);
|
|
208
211
|
var alignedClassName = React.useMemo(function () {
|
|
209
212
|
var baseClassName = getAlignPopupClassName(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
package/es/interface.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface AlignType {
|
|
|
33
33
|
};
|
|
34
34
|
/** Auto adjust arrow position */
|
|
35
35
|
autoArrow?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Config visible region check of html node. Default `visible`:
|
|
38
|
+
* - `visible`: The visible region of user browser window. Use `clientHeight` for check.
|
|
39
|
+
* - `scroll`: The whole region of the html scroll area. Use `scrollHeight` for check.
|
|
40
|
+
*/
|
|
41
|
+
htmlRegion?: 'visible' | 'scroll';
|
|
36
42
|
/**
|
|
37
43
|
* Whether use css right instead of left to position
|
|
38
44
|
*/
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -92,6 +92,9 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
92
92
|
var doc = popupElement.ownerDocument;
|
|
93
93
|
var win = (0, _util.getWin)(popupElement);
|
|
94
94
|
|
|
95
|
+
// Placement
|
|
96
|
+
var placementInfo = builtinPlacements[placement] || popupAlign || {};
|
|
97
|
+
|
|
95
98
|
// Reset first
|
|
96
99
|
popupElement.style.left = '0';
|
|
97
100
|
popupElement.style.top = '0';
|
|
@@ -120,12 +123,23 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
120
123
|
height = _win$getComputedStyle.height;
|
|
121
124
|
var _doc$documentElement = doc.documentElement,
|
|
122
125
|
clientWidth = _doc$documentElement.clientWidth,
|
|
123
|
-
clientHeight = _doc$documentElement.clientHeight
|
|
126
|
+
clientHeight = _doc$documentElement.clientHeight,
|
|
127
|
+
scrollWidth = _doc$documentElement.scrollWidth,
|
|
128
|
+
scrollHeight = _doc$documentElement.scrollHeight,
|
|
129
|
+
scrollTop = _doc$documentElement.scrollTop,
|
|
130
|
+
scrollLeft = _doc$documentElement.scrollLeft;
|
|
124
131
|
var popupHeight = popupRect.height;
|
|
125
132
|
var popupWidth = popupRect.width;
|
|
126
133
|
|
|
127
134
|
// Get bounding of visible area
|
|
128
|
-
var visibleArea =
|
|
135
|
+
var visibleArea = placementInfo.htmlRegion === 'scroll' ?
|
|
136
|
+
// Scroll region should take scrollLeft & scrollTop into account
|
|
137
|
+
{
|
|
138
|
+
left: -scrollLeft,
|
|
139
|
+
top: -scrollTop,
|
|
140
|
+
right: scrollWidth - scrollLeft,
|
|
141
|
+
bottom: scrollHeight - scrollTop
|
|
142
|
+
} : {
|
|
129
143
|
left: 0,
|
|
130
144
|
top: 0,
|
|
131
145
|
right: clientWidth,
|
|
@@ -139,10 +153,10 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
139
153
|
eleInnerWidth = ele.clientWidth;
|
|
140
154
|
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
141
155
|
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
142
|
-
var
|
|
143
|
-
var
|
|
144
|
-
var eleRight = eleRect.x + eleRect.width -
|
|
145
|
-
var eleBottom = eleRect.y + eleRect.height -
|
|
156
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth) * scaleX;
|
|
157
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight) * scaleY;
|
|
158
|
+
var eleRight = eleRect.x + eleRect.width - eleScrollWidth;
|
|
159
|
+
var eleBottom = eleRect.y + eleRect.height - eleScrollHeight;
|
|
146
160
|
visibleArea.left = Math.max(visibleArea.left, eleRect.left);
|
|
147
161
|
visibleArea.top = Math.max(visibleArea.top, eleRect.top);
|
|
148
162
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
@@ -157,9 +171,6 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
157
171
|
var _scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
158
172
|
var _scaleY = toNum(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
|
|
159
173
|
|
|
160
|
-
// Placement
|
|
161
|
-
var placementInfo = popupAlign || builtinPlacements[placement] || {};
|
|
162
|
-
|
|
163
174
|
// Offset
|
|
164
175
|
var offset = placementInfo.offset,
|
|
165
176
|
targetOffset = placementInfo.targetOffset;
|
package/lib/index.js
CHANGED
|
@@ -210,9 +210,12 @@ function generateTrigger() {
|
|
|
210
210
|
(0, _useLayoutEffect.default)(function () {
|
|
211
211
|
triggerAlign();
|
|
212
212
|
}, [mousePos]);
|
|
213
|
+
|
|
214
|
+
// When no builtinPlacements and popupAlign changed
|
|
213
215
|
(0, _useLayoutEffect.default)(function () {
|
|
214
|
-
if (!
|
|
215
|
-
|
|
216
|
+
if (mergedOpen && !(builtinPlacements !== null && builtinPlacements !== void 0 && builtinPlacements[popupPlacement])) {
|
|
217
|
+
triggerAlign();
|
|
218
|
+
}
|
|
216
219
|
}, [JSON.stringify(popupAlign)]);
|
|
217
220
|
var alignedClassName = React.useMemo(function () {
|
|
218
221
|
var baseClassName = (0, _util.getAlignPopupClassName)(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
package/lib/interface.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface AlignType {
|
|
|
33
33
|
};
|
|
34
34
|
/** Auto adjust arrow position */
|
|
35
35
|
autoArrow?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Config visible region check of html node. Default `visible`:
|
|
38
|
+
* - `visible`: The visible region of user browser window. Use `clientHeight` for check.
|
|
39
|
+
* - `scroll`: The whole region of the html scroll area. Use `scrollHeight` for check.
|
|
40
|
+
*/
|
|
41
|
+
htmlRegion?: 'visible' | 'scroll';
|
|
36
42
|
/**
|
|
37
43
|
* Whether use css right instead of left to position
|
|
38
44
|
*/
|