@ultraviolet/ui 1.26.0 → 1.26.1

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.
@@ -48,6 +48,35 @@ const computePlacement = _ref => {
48
48
  }
49
49
  return 'top';
50
50
  };
51
+
52
+ /**
53
+ * This function will check if the offset parent is usable for popup positioning
54
+ * If not it will loop and search for a compatible parent until document.body is reached
55
+ */
56
+ const findOffsetParent = element => {
57
+ const offsetParent = element?.current?.offsetParent;
58
+
59
+ // We need to check if offsetParent is a table cell or a table because they are not suitable for positioning
60
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
61
+ if (offsetParent && !['TH', 'TD', 'TABLE'].includes(offsetParent.tagName)) {
62
+ return offsetParent;
63
+ }
64
+ let currentElement = element?.current;
65
+ while (currentElement && currentElement.tagName !== 'BODY') {
66
+ const {
67
+ position
68
+ } = window.getComputedStyle(currentElement);
69
+
70
+ // Check if the current element is a potential offset parent
71
+ if (position !== 'static') {
72
+ return currentElement;
73
+ }
74
+ currentElement = currentElement.parentElement;
75
+ }
76
+
77
+ // If no suitable offset parent is found, return the body element
78
+ return document.body;
79
+ };
51
80
  /**
52
81
  * This function will compute the positions of popup and arrow based on children position and popup size
53
82
  */
@@ -58,17 +87,18 @@ const computePositions = _ref2 => {
58
87
  popupRef,
59
88
  popupPortalTarget
60
89
  } = _ref2;
61
- const childrenStructuredRef = childrenRef.current.getBoundingClientRect();
62
- const offsetParentRect = childrenRef?.current?.offsetParent?.getBoundingClientRect() ?? {
90
+ const childrenRect = childrenRef.current.getBoundingClientRect();
91
+ const offsetParent = findOffsetParent(childrenRef);
92
+ const offsetParentRect = offsetParent?.getBoundingClientRect() ?? {
63
93
  top: 0,
64
94
  left: 0,
65
95
  right: 0
66
96
  };
67
97
  const popupStructuredRef = popupRef.current.getBoundingClientRect();
68
98
  const placementBasedOnWindowSize = placement === 'auto' ? computePlacement({
69
- childrenStructuredRef,
99
+ childrenStructuredRef: childrenRect,
70
100
  popupStructuredRef,
71
- offsetParentRect: offsetParentRect,
101
+ offsetParentRect,
72
102
  popupPortalTarget
73
103
  }) : placement;
74
104
  const {
@@ -77,7 +107,7 @@ const computePositions = _ref2 => {
77
107
  right: childrenRight,
78
108
  width: childrenWidth,
79
109
  height: childrenHeight
80
- } = childrenStructuredRef;
110
+ } = childrenRect;
81
111
  const {
82
112
  top: parentTop,
83
113
  left: parentLeft,
@@ -88,13 +118,16 @@ const computePositions = _ref2 => {
88
118
  height: popupHeight
89
119
  } = popupStructuredRef;
90
120
 
121
+ // offSetParent is the closest positioned ancestor. If the element is not positioned, the nearest table cell or root element is used.
122
+ const isPopupPortalTargetBody = popupPortalTarget === document.body || offsetParent === document.body;
123
+
91
124
  // It will get how much scroll is done on the page to compute the position of the popup
92
- const scrollTopValue = popupPortalTarget === document.body ? document.documentElement.scrollTop : 0;
125
+ const scrollTopValue = isPopupPortalTargetBody ? document.documentElement.scrollTop : 0;
93
126
 
94
127
  // We need to compute the position of the popup based on the parent element in the case the popup is not in the body
95
- const overloadedChildrenLeft = popupPortalTarget === document.body ? childrenLeft : childrenLeft - parentLeft;
96
- const overloadedChildrenTop = popupPortalTarget === document.body ? childrenTop : childrenTop - parentTop;
97
- const overloadedChildrenRight = popupPortalTarget === document.body ? childrenRight : childrenRight + childrenWidth + ARROW_WIDTH + SPACE - parentRight / 2;
128
+ const overloadedChildrenLeft = isPopupPortalTargetBody ? childrenLeft : childrenLeft - parentLeft;
129
+ const overloadedChildrenTop = isPopupPortalTargetBody ? childrenTop : childrenTop - parentTop;
130
+ const overloadedChildrenRight = isPopupPortalTargetBody ? childrenRight : childrenRight + childrenWidth + ARROW_WIDTH + SPACE - parentRight / 2;
98
131
  switch (placementBasedOnWindowSize) {
99
132
  case 'bottom':
100
133
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -62,7 +62,7 @@
62
62
  "deepmerge": "4.3.1",
63
63
  "react-datepicker": "4.21.0",
64
64
  "react-flatten-children": "1.1.2",
65
- "react-select": "5.7.7",
65
+ "react-select": "5.8.0",
66
66
  "react-toastify": "9.1.3",
67
67
  "react-use-clipboard": "1.0.9",
68
68
  "reakit": "1.3.11",