x-ui-design 0.2.97 → 0.2.98
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/dist/index.esm.js +48 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +48 -10
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +57 -11
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3025,27 +3025,64 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3025
3025
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
3026
3026
|
};
|
|
3027
3027
|
}, [handleClearInputValue, open, hasMode]);
|
|
3028
|
-
|
|
3029
|
-
if (!selectRef.current
|
|
3030
|
-
return;
|
|
3031
|
-
}
|
|
3028
|
+
const updateDropdownPosition = useCallback(() => {
|
|
3029
|
+
if (!selectRef.current) return;
|
|
3032
3030
|
const selectBox = selectRef.current.getBoundingClientRect();
|
|
3033
3031
|
const dropdownHeight = listHeight;
|
|
3034
3032
|
const windowHeight = window.innerHeight;
|
|
3035
3033
|
const spaceBelow = windowHeight - selectBox.bottom;
|
|
3036
3034
|
const spaceAbove = selectBox.top;
|
|
3037
3035
|
let positionStyle = {
|
|
3038
|
-
top: `${selectBox.bottom}px
|
|
3039
|
-
|
|
3036
|
+
top: `${selectBox.bottom + window.scrollY}px`,
|
|
3037
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3038
|
+
width: `${selectBox.width}px`,
|
|
3039
|
+
position: 'absolute'
|
|
3040
3040
|
};
|
|
3041
3041
|
if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
|
|
3042
3042
|
positionStyle = {
|
|
3043
|
-
top: `${selectBox.top - dropdownHeight}px
|
|
3044
|
-
|
|
3043
|
+
top: `${selectBox.top + window.scrollY - dropdownHeight}px`,
|
|
3044
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3045
|
+
width: `${selectBox.width}px`,
|
|
3046
|
+
position: 'absolute'
|
|
3045
3047
|
};
|
|
3046
3048
|
}
|
|
3047
3049
|
setDropdownPosition(positionStyle);
|
|
3048
|
-
}, [listHeight
|
|
3050
|
+
}, [listHeight]);
|
|
3051
|
+
useEffect(() => {
|
|
3052
|
+
if (!isOpen) return;
|
|
3053
|
+
updateDropdownPosition();
|
|
3054
|
+
// const container = getPopupContainer?.(selectRef.current!);
|
|
3055
|
+
const scrollableParents = getScrollParents(selectRef.current);
|
|
3056
|
+
const handleScroll = () => {
|
|
3057
|
+
updateDropdownPosition();
|
|
3058
|
+
};
|
|
3059
|
+
// Add scroll listeners to all scrollable parents
|
|
3060
|
+
scrollableParents.forEach(el => {
|
|
3061
|
+
el.addEventListener('scroll', handleScroll, {
|
|
3062
|
+
passive: true
|
|
3063
|
+
});
|
|
3064
|
+
});
|
|
3065
|
+
// Add resize listener
|
|
3066
|
+
window.addEventListener('resize', updateDropdownPosition);
|
|
3067
|
+
return () => {
|
|
3068
|
+
scrollableParents.forEach(el => {
|
|
3069
|
+
el.removeEventListener('scroll', handleScroll);
|
|
3070
|
+
});
|
|
3071
|
+
window.removeEventListener('resize', updateDropdownPosition);
|
|
3072
|
+
};
|
|
3073
|
+
}, [isOpen, getPopupContainer, updateDropdownPosition]);
|
|
3074
|
+
// Helper function to get all scrollable parents
|
|
3075
|
+
const getScrollParents = element => {
|
|
3076
|
+
const parents = [];
|
|
3077
|
+
let current = element.parentElement;
|
|
3078
|
+
while (current) {
|
|
3079
|
+
if (current.scrollHeight > current.clientHeight) {
|
|
3080
|
+
parents.push(current);
|
|
3081
|
+
}
|
|
3082
|
+
current = current.parentElement;
|
|
3083
|
+
}
|
|
3084
|
+
return parents;
|
|
3085
|
+
};
|
|
3049
3086
|
const handleSearch = e => {
|
|
3050
3087
|
setSearchQuery(e.target.value);
|
|
3051
3088
|
onSearch?.(e.target.value);
|
|
@@ -3137,7 +3174,8 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3137
3174
|
}));
|
|
3138
3175
|
}, [showArrow, showSearch, isOpen, suffixIcon]);
|
|
3139
3176
|
const popupContainer = useMemo(() => {
|
|
3140
|
-
|
|
3177
|
+
if (typeof window === 'undefined') return null;
|
|
3178
|
+
return selectRef.current ? getPopupContainer?.(selectRef.current) : document.body;
|
|
3141
3179
|
}, [getPopupContainer]);
|
|
3142
3180
|
const extractedOptions = children ? (Array.isArray(children) ? children : [children]).filter(e => e).map(child => child.props) : options;
|
|
3143
3181
|
const filteredOptions = extractedOptions.filter(option => {
|