x-ui-design 0.2.97 → 0.2.99

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);
@@ -237,7 +282,7 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
237
282
  const updatedSelected = [...selected, newOptionValue];
238
283
 
239
284
  onChange?.(updatedSelected);
240
- onSelect?.(newOptionValue);
285
+ onSelect?.(updatedSelected);
241
286
 
242
287
  const input = selectRef.current?.querySelector('input');
243
288
 
@@ -269,6 +314,7 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
269
314
 
270
315
  setSelected(newSelection);
271
316
  onChange?.(newSelection, option);
317
+ onSelect?.(newSelection, option);
272
318
 
273
319
  if (selected.includes(optionValue)) {
274
320
  onDeselect?.(optionValue, option);
@@ -290,6 +336,7 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
290
336
 
291
337
  setSelected(value);
292
338
  onChange?.('');
339
+ onSelect?.('');
293
340
  onClear?.();
294
341
 
295
342
  handleClearInputValue();
@@ -301,6 +348,7 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
301
348
  : e.target.value;
302
349
 
303
350
  onChange?.(updatedSelected);
351
+ onSelect?.(updatedSelected);
304
352
  setSelected(updatedSelected);
305
353
  };
306
354
 
@@ -341,6 +389,7 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
341
389
  : searchQuery.trim();
342
390
 
343
391
  onChange?.(updatedSelected);
392
+ onSelect?.(updatedSelected);
344
393
  setSelected(updatedSelected);
345
394
  }
346
395
 
@@ -363,9 +412,11 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
363
412
  }, [showArrow, showSearch, isOpen, suffixIcon]);
364
413
 
365
414
  const popupContainer = useMemo(() => {
415
+ if (typeof window === 'undefined') return null;
416
+
366
417
  return selectRef.current
367
418
  ? getPopupContainer?.(selectRef.current)
368
- : selectRef.current;
419
+ : document.body;
369
420
  }, [getPopupContainer]);
370
421
 
371
422
  const extractedOptions = children
@@ -450,7 +501,6 @@ const SelectComponent = forwardRef<HTMLDivElement, SelectProps>(
450
501
  return;
451
502
  }
452
503
 
453
-
454
504
  handleSelect(
455
505
  e as MouseEventHandlerSelect,
456
506
  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.99",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -3,6 +3,9 @@
3
3
  import { Select } from "../../lib/components/Select";
4
4
  import { Option } from "../../lib/components/Select/Option";
5
5
 
6
+ import { Select as AntSelect } from 'antd';
7
+ import { Option as AntOption } from 'antd/es/mentions';
8
+
6
9
  export const CountryCodes = [...new Set([
7
10
  {
8
11
  "label": "Afghanistan Afghanistan Afghanistan Afghanistan Afghanistan Afghanistan Afghanistan Afghanistan",
@@ -1823,8 +1826,7 @@ export default function Home() {
1823
1826
 
1824
1827
  return (
1825
1828
  <>
1826
- <Select style={{ width: 500 }} showSearch onChange={(e) => {console.log(e)
1827
- }}>
1829
+ <Select showSearch onSelect={(e) => {console.log(e)}} onChange={(e) => {console.log(e)}}>
1828
1830
  {CountryCodes.map(country => (
1829
1831
  <Option
1830
1832
  key={country.value}
@@ -1841,6 +1843,24 @@ export default function Home() {
1841
1843
  </Option>
1842
1844
  ))}
1843
1845
  </Select>
1846
+
1847
+ <AntSelect showSearch onSelect={(e) => {console.log(e)}} onChange={(e) => {console.log(e)}}>
1848
+ {CountryCodes.map(country => (
1849
+ <AntOption
1850
+ key={country.value}
1851
+ value={country.value}
1852
+ >
1853
+ <div
1854
+ className="countyCode"
1855
+ title={country.label}
1856
+ >
1857
+ <div dir="ltr" className="phoneCode">
1858
+ {country.label}
1859
+ </div>
1860
+ </div>
1861
+ </AntOption>
1862
+ ))}
1863
+ </AntSelect>
1844
1864
  </>
1845
1865
  )
1846
1866
  }