x-ui-design 0.7.52 → 0.7.53

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 CHANGED
@@ -2841,59 +2841,42 @@ const TimePicker = ({
2841
2841
  });
2842
2842
  };
2843
2843
  const dropdownPossition = useCallback(() => {
2844
- if (!inputRef.current) {
2845
- return {};
2846
- }
2847
- const scrollableParents = getScrollParents(inputRef.current)[1];
2848
- const offsetHeight = getPopupContainer ? window.innerHeight : scrollableParents?.offsetHeight;
2849
- const shouldShowAbove = offsetHeight - (inputRef.current?.getBoundingClientRect().bottom || 0) < 230;
2850
- const shouldShowBelow = inputRef.current?.getBoundingClientRect().top < 230;
2844
+ if (!inputRef.current) return {};
2845
+ const inputRect = inputRef.current.getBoundingClientRect();
2846
+ const popupEl = popupRef.current;
2847
+ const dropdownHeight = popupEl?.offsetHeight || 230;
2848
+ // 1️⃣ Determine the container for popup
2849
+ const popupContainer = getPopupContainer ? getPopupContainer(document.body) : getScrollParents(inputRef.current)[1] || document.body;
2850
+ const containerRect = popupContainer.getBoundingClientRect();
2851
+ // 2️⃣ Compute visible space inside the container
2852
+ const spaceAbove = inputRect.top - containerRect.top;
2853
+ const spaceBelow = containerRect.bottom - inputRect.bottom;
2854
+ const shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
2855
+ const shouldShowBelow = !shouldShowAbove;
2856
+ // Debug
2851
2857
  console.log({
2852
- shouldShowBelow,
2853
- shouldShowAbove
2858
+ container: popupContainer,
2859
+ spaceAbove,
2860
+ spaceBelow,
2861
+ shouldShowAbove,
2862
+ shouldShowBelow
2854
2863
  });
2855
- if (open && !shouldShowBelow && !shouldShowAbove) {
2856
- setDropdownPosition(previousDropdownPosition => {
2857
- if (!Object.keys(previousDropdownPosition).length) {
2858
- if (getPopupContainer) {
2859
- return {
2860
- top: (inputRef.current?.getBoundingClientRect().top || 0) + document.documentElement.scrollTop - 230,
2861
- left: (inputRef.current?.getBoundingClientRect().left || 0) + document.documentElement.scrollLeft
2862
- };
2863
- } else {
2864
- return {
2865
- top: (inputRef.current?.offsetTop || 0) + (inputRef.current?.offsetHeight || 0),
2866
- left: inputRef.current?.offsetLeft
2867
- };
2868
- }
2869
- }
2870
- return previousDropdownPosition;
2871
- });
2872
- }
2864
+ // 3️⃣ Compute the position
2873
2865
  if (getPopupContainer) {
2874
- if (!shouldShowBelow) {
2875
- toBelow();
2876
- return;
2877
- }
2878
- if (!shouldShowAbove) {
2866
+ // Position relative to container (like Antd with custom popup container)
2867
+ if (shouldShowAbove) {
2879
2868
  toAbove();
2869
+ } else {
2870
+ toBelow();
2880
2871
  }
2881
2872
  } else {
2882
- if (shouldShowBelow) {
2883
- setDropdownPosition({
2884
- top: inputRef.current.offsetTop + inputRef.current.offsetHeight,
2885
- left: inputRef.current?.offsetLeft
2886
- });
2887
- return;
2888
- }
2889
- if (shouldShowAbove) {
2890
- setDropdownPosition({
2891
- top: inputRef.current?.offsetHeight - inputRef.current.offsetHeight - (popupRef.current?.offsetHeight || 0) - 8,
2892
- left: inputRef.current?.offsetLeft
2893
- });
2894
- }
2873
+ // Position relative to nearest scrollable container (Antd default)
2874
+ setDropdownPosition({
2875
+ top: shouldShowAbove ? inputRef.current.offsetTop - (popupEl?.offsetHeight || dropdownHeight) - 8 : inputRef.current.offsetTop + inputRef.current.offsetHeight,
2876
+ left: inputRef.current.offsetLeft
2877
+ });
2895
2878
  }
2896
- }, [open, inputRef.current]);
2879
+ }, [open, getPopupContainer]);
2897
2880
  const getScrollParents = useCallback(element => {
2898
2881
  const parents = [];
2899
2882
  let current = element.parentElement;