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