pixuireactcomponents 1.5.28 → 1.5.29
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/package.json
CHANGED
|
@@ -35,20 +35,27 @@ export var DropDown = function (props) {
|
|
|
35
35
|
var elementStyleOrClass = getElementStyleOrClass();
|
|
36
36
|
var _a = useState(false), spread = _a[0], setSpread = _a[1];
|
|
37
37
|
var dropdownRef = useRef(null);
|
|
38
|
+
var dropdownContentRef = useRef(null);
|
|
38
39
|
useEffect(function () {
|
|
39
40
|
onSpread && onSpread(spread);
|
|
40
41
|
}, [spread]);
|
|
41
42
|
useEffect(function () {
|
|
42
43
|
var handleClickOutside = function (event) {
|
|
43
44
|
// console.log('handleClickOutside, ', event.clientX, event.clientY)
|
|
44
|
-
if (dropdownRef.current) {
|
|
45
|
+
if (dropdownRef.current && dropdownContentRef.current) {
|
|
45
46
|
var dropDownRect = dropdownRef.current.getBoundingClientRect();
|
|
47
|
+
var contentRect = dropdownContentRef.current.getBoundingClientRect();
|
|
46
48
|
// console.log('dropDownRect', dropDownRect, 'isOutside', event.clientX < dropDownRect.left, 'isOutside', event.clientX > dropDownRect.right, 'isOutside', event.clientY < dropDownRect.top, 'isOutside', event.clientY > dropDownRect.bottom)
|
|
47
|
-
|
|
49
|
+
// console.log('contentRect', contentRect, 'isOutside', event.clientX < contentRect.left, 'isOutside', event.clientX > contentRect.right, 'isOutside', event.clientY < contentRect.top, 'isOutside', event.clientY > contentRect.bottom)
|
|
50
|
+
var isOutsideDropdown = event.clientX < dropDownRect.left ||
|
|
48
51
|
event.clientX > dropDownRect.right ||
|
|
49
52
|
event.clientY < dropDownRect.top ||
|
|
50
53
|
event.clientY > dropDownRect.bottom;
|
|
51
|
-
|
|
54
|
+
var isOutsideContent = event.clientX < contentRect.left ||
|
|
55
|
+
event.clientX > contentRect.right ||
|
|
56
|
+
event.clientY < contentRect.top ||
|
|
57
|
+
event.clientY > contentRect.bottom;
|
|
58
|
+
if (isOutsideDropdown && isOutsideContent) {
|
|
52
59
|
setSpread(false);
|
|
53
60
|
}
|
|
54
61
|
}
|
|
@@ -87,7 +94,7 @@ export var DropDown = function (props) {
|
|
|
87
94
|
overlayRender,
|
|
88
95
|
spread && (
|
|
89
96
|
//在下方展开
|
|
90
|
-
h("div", { className: typeof elementStyleOrClass.dropdownBg === 'string' ? elementStyleOrClass.dropdownBg : '', style: __assign({ flexDirection: 'column', overflow: 'scroll' }, (typeof elementStyleOrClass.dropdownBg === 'object' ? elementStyleOrClass.dropdownBg : undefined)) }, options.map(function (option, index) {
|
|
97
|
+
h("div", { ref: dropdownContentRef, className: typeof elementStyleOrClass.dropdownBg === 'string' ? elementStyleOrClass.dropdownBg : '', style: __assign({ flexDirection: 'column', overflow: 'scroll' }, (typeof elementStyleOrClass.dropdownBg === 'object' ? elementStyleOrClass.dropdownBg : undefined)) }, options.map(function (option, index) {
|
|
91
98
|
return (h("div", null, optionRender(option)));
|
|
92
99
|
})))));
|
|
93
100
|
};
|