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.
@@ -182,10 +182,8 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
182
182
  };
183
183
  }, [handleClearInputValue, open, hasMode]);
184
184
 
185
- useEffect(() => {
186
- if (!selectRef.current || !getPopupContainer) {
187
- return;
188
- }
185
+ const updateDropdownPosition = useCallback(() => {
186
+ if (!selectRef.current) return;
189
187
 
190
188
  const selectBox = selectRef.current.getBoundingClientRect();
191
189
  const dropdownHeight = listHeight;
@@ -194,19 +192,66 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
194
192
  const spaceAbove = selectBox.top;
195
193
 
196
194
  let positionStyle: CSSProperties = {
197
- top: `${selectBox.bottom}px`,
198
- // left: `${selectBox.left}px`,
195
+ top: `${selectBox.bottom + window.scrollY}px`,
196
+ left: `${selectBox.left + window.scrollX}px`,
197
+ width: `${selectBox.width}px`,
198
+ position: 'absolute',
199
199
  };
200
200
 
201
201
  if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
202
202
  positionStyle = {
203
- top: `${selectBox.top - dropdownHeight}px`,
204
- // left: `${selectBox.left}px`,
203
+ top: `${selectBox.top + window.scrollY - dropdownHeight}px`,
204
+ left: `${selectBox.left + window.scrollX}px`,
205
+ width: `${selectBox.width}px`,
206
+ position: 'absolute',
205
207
  };
206
208
  }
207
209
 
208
210
  setDropdownPosition(positionStyle);
209
- }, [listHeight, getPopupContainer]);
211
+ }, [listHeight]);
212
+
213
+ useEffect(() => {
214
+ if (!isOpen) return;
215
+
216
+ updateDropdownPosition();
217
+
218
+ // const container = getPopupContainer?.(selectRef.current!);
219
+ const scrollableParents = getScrollParents(selectRef.current!);
220
+
221
+ const handleScroll = () => {
222
+ updateDropdownPosition();
223
+ };
224
+
225
+ // Add scroll listeners to all scrollable parents
226
+ scrollableParents.forEach(el => {
227
+ el.addEventListener('scroll', handleScroll, { passive: true });
228
+ });
229
+
230
+ // Add resize listener
231
+ window.addEventListener('resize', updateDropdownPosition);
232
+
233
+ return () => {
234
+ scrollableParents.forEach(el => {
235
+ el.removeEventListener('scroll', handleScroll);
236
+ });
237
+ window.removeEventListener('resize', updateDropdownPosition);
238
+ };
239
+ }, [isOpen, getPopupContainer, updateDropdownPosition]);
240
+
241
+ // Helper function to get all scrollable parents
242
+ const getScrollParents = (element: HTMLElement): HTMLElement[] => {
243
+ const parents: HTMLElement[] = [];
244
+ let current = element.parentElement;
245
+
246
+ while (current) {
247
+ if (current.scrollHeight > current.clientHeight) {
248
+ parents.push(current);
249
+ }
250
+ current = current.parentElement;
251
+ }
252
+
253
+ return parents;
254
+ };
210
255
 
211
256
  const handleSearch = (e: SyntheticBaseEvent) => {
212
257
  setSearchQuery(e.target.value as string);
@@ -363,9 +408,11 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
363
408
  }, [showArrow, showSearch, isOpen, suffixIcon]);
364
409
 
365
410
  const popupContainer = useMemo(() => {
411
+ if (typeof window === 'undefined') return null;
412
+
366
413
  return selectRef.current
367
414
  ? getPopupContainer?.(selectRef.current)
368
- : selectRef.current;
415
+ : document.body;
369
416
  }, [getPopupContainer]);
370
417
 
371
418
  const extractedOptions = children
@@ -450,7 +497,6 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
450
497
  return;
451
498
  }
452
499
 
453
-
454
500
  handleSelect(
455
501
  e as MouseEventHandlerSelect,
456
502
  props.value as string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "0.2.97",
3
+ "version": "0.2.98",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",