x-ui-design 0.7.51 → 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,55 +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;
2851
- if (open && !shouldShowBelow && !shouldShowAbove) {
2852
- setDropdownPosition(previousDropdownPosition => {
2853
- if (!Object.keys(previousDropdownPosition).length) {
2854
- if (getPopupContainer) {
2855
- return {
2856
- top: (inputRef.current?.getBoundingClientRect().top || 0) + document.documentElement.scrollTop - 230,
2857
- left: (inputRef.current?.getBoundingClientRect().left || 0) + document.documentElement.scrollLeft
2858
- };
2859
- } else {
2860
- return {
2861
- top: (inputRef.current?.offsetTop || 0) + (inputRef.current?.offsetHeight || 0),
2862
- left: inputRef.current?.offsetLeft
2863
- };
2864
- }
2865
- }
2866
- return previousDropdownPosition;
2867
- });
2868
- }
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
2857
+ console.log({
2858
+ container: popupContainer,
2859
+ spaceAbove,
2860
+ spaceBelow,
2861
+ shouldShowAbove,
2862
+ shouldShowBelow
2863
+ });
2864
+ // 3️⃣ Compute the position
2869
2865
  if (getPopupContainer) {
2870
- if (!shouldShowBelow) {
2871
- toBelow();
2872
- return;
2873
- }
2874
- if (!shouldShowAbove) {
2866
+ // Position relative to container (like Antd with custom popup container)
2867
+ if (shouldShowAbove) {
2875
2868
  toAbove();
2869
+ } else {
2870
+ toBelow();
2876
2871
  }
2877
2872
  } else {
2878
- if (shouldShowBelow) {
2879
- setDropdownPosition({
2880
- top: inputRef.current.offsetTop + inputRef.current.offsetHeight,
2881
- left: inputRef.current?.offsetLeft
2882
- });
2883
- return;
2884
- }
2885
- if (shouldShowAbove) {
2886
- setDropdownPosition({
2887
- top: inputRef.current?.offsetHeight - inputRef.current.offsetHeight - (popupRef.current?.offsetHeight || 0) - 8,
2888
- left: inputRef.current?.offsetLeft
2889
- });
2890
- }
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
+ });
2891
2878
  }
2892
- }, [open, inputRef.current]);
2879
+ }, [open, getPopupContainer]);
2893
2880
  const getScrollParents = useCallback(element => {
2894
2881
  const parents = [];
2895
2882
  let current = element.parentElement;