@react-aria/utils 3.25.2 → 3.26.0

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.
Files changed (59) hide show
  1. package/dist/focusWithoutScrolling.main.js +1 -1
  2. package/dist/focusWithoutScrolling.main.js.map +1 -1
  3. package/dist/focusWithoutScrolling.mjs +1 -1
  4. package/dist/focusWithoutScrolling.module.js +1 -1
  5. package/dist/focusWithoutScrolling.module.js.map +1 -1
  6. package/dist/isScrollable.main.js +1 -0
  7. package/dist/isScrollable.main.js.map +1 -1
  8. package/dist/isScrollable.mjs +1 -0
  9. package/dist/isScrollable.module.js +1 -0
  10. package/dist/isScrollable.module.js.map +1 -1
  11. package/dist/mergeProps.main.js.map +1 -1
  12. package/dist/mergeProps.module.js.map +1 -1
  13. package/dist/openLink.main.js +6 -2
  14. package/dist/openLink.main.js.map +1 -1
  15. package/dist/openLink.mjs +6 -2
  16. package/dist/openLink.module.js +6 -2
  17. package/dist/openLink.module.js.map +1 -1
  18. package/dist/scrollIntoView.main.js +1 -1
  19. package/dist/scrollIntoView.main.js.map +1 -1
  20. package/dist/scrollIntoView.mjs +1 -1
  21. package/dist/scrollIntoView.module.js +1 -1
  22. package/dist/scrollIntoView.module.js.map +1 -1
  23. package/dist/types.d.ts +24 -24
  24. package/dist/types.d.ts.map +1 -1
  25. package/dist/useDescription.main.js.map +1 -1
  26. package/dist/useDescription.module.js.map +1 -1
  27. package/dist/useFormReset.main.js.map +1 -1
  28. package/dist/useFormReset.module.js.map +1 -1
  29. package/dist/useGlobalListeners.main.js +0 -1
  30. package/dist/useGlobalListeners.main.js.map +1 -1
  31. package/dist/useGlobalListeners.mjs +0 -1
  32. package/dist/useGlobalListeners.module.js +0 -1
  33. package/dist/useGlobalListeners.module.js.map +1 -1
  34. package/dist/useId.main.js +16 -7
  35. package/dist/useId.main.js.map +1 -1
  36. package/dist/useId.mjs +16 -7
  37. package/dist/useId.module.js +16 -7
  38. package/dist/useId.module.js.map +1 -1
  39. package/dist/useLoadMore.main.js +2 -1
  40. package/dist/useLoadMore.main.js.map +1 -1
  41. package/dist/useLoadMore.mjs +2 -1
  42. package/dist/useLoadMore.module.js +2 -1
  43. package/dist/useLoadMore.module.js.map +1 -1
  44. package/dist/useViewportSize.main.js +0 -1
  45. package/dist/useViewportSize.main.js.map +1 -1
  46. package/dist/useViewportSize.mjs +0 -1
  47. package/dist/useViewportSize.module.js +0 -1
  48. package/dist/useViewportSize.module.js.map +1 -1
  49. package/package.json +6 -6
  50. package/src/focusWithoutScrolling.ts +1 -1
  51. package/src/isScrollable.ts +4 -1
  52. package/src/mergeProps.ts +1 -1
  53. package/src/openLink.tsx +5 -3
  54. package/src/scrollIntoView.ts +3 -3
  55. package/src/useFormReset.ts +1 -1
  56. package/src/useGlobalListeners.ts +1 -1
  57. package/src/useId.ts +13 -8
  58. package/src/useLoadMore.ts +3 -3
  59. package/src/useViewportSize.ts +0 -1
package/src/openLink.tsx CHANGED
@@ -148,8 +148,9 @@ function openSyntheticLink(target: Element, modifiers: Modifiers) {
148
148
 
149
149
  export function useSyntheticLinkProps(props: LinkDOMProps) {
150
150
  let router = useRouter();
151
+ const href = router.useHref(props.href ?? '');
151
152
  return {
152
- 'data-href': props.href ? router.useHref(props.href) : undefined,
153
+ 'data-href': props.href ? href : undefined,
153
154
  'data-target': props.target,
154
155
  'data-rel': props.rel,
155
156
  'data-download': props.download,
@@ -170,10 +171,11 @@ export function getSyntheticLinkProps(props: LinkDOMProps) {
170
171
  };
171
172
  }
172
173
 
173
- export function useLinkProps(props: LinkDOMProps) {
174
+ export function useLinkProps(props?: LinkDOMProps) {
174
175
  let router = useRouter();
176
+ const href = router.useHref(props?.href ?? '');
175
177
  return {
176
- href: props?.href ? router.useHref(props?.href) : undefined,
178
+ href: props?.href ? href : undefined,
177
179
  target: props?.target,
178
180
  rel: props?.rel,
179
181
  download: props?.download,
@@ -14,7 +14,7 @@ import {getScrollParents} from './getScrollParents';
14
14
 
15
15
  interface ScrollIntoViewportOpts {
16
16
  /** The optional containing element of the target to be centered in the viewport. */
17
- containingElement?: Element
17
+ containingElement?: Element | null
18
18
  }
19
19
 
20
20
  /**
@@ -81,8 +81,8 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
81
81
  * that will be centered in the viewport prior to scrolling the targetElement into view. If scrolling is prevented on
82
82
  * the body (e.g. targetElement is in a popover), this will only scroll the scroll parents of the targetElement up to but not including the body itself.
83
83
  */
84
- export function scrollIntoViewport(targetElement: Element, opts?: ScrollIntoViewportOpts) {
85
- if (document.contains(targetElement)) {
84
+ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts) {
85
+ if (targetElement && document.contains(targetElement)) {
86
86
  let root = document.scrollingElement || document.documentElement;
87
87
  let isScrollPrevented = window.getComputedStyle(root).overflow === 'hidden';
88
88
  // If scrolling is not currently prevented then we aren’t in a overlay nor is a overlay open, just use element.scrollIntoView to bring the element into view
@@ -15,7 +15,7 @@ import {useEffect, useRef} from 'react';
15
15
  import {useEffectEvent} from './useEffectEvent';
16
16
 
17
17
  export function useFormReset<T>(
18
- ref: RefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null>,
18
+ ref: RefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null> | undefined,
19
19
  initialValue: T,
20
20
  onReset: (value: T) => void
21
21
  ) {
@@ -42,7 +42,7 @@ export function useGlobalListeners(): GlobalListeners {
42
42
  });
43
43
  }, [removeGlobalListener]);
44
44
 
45
- // eslint-disable-next-line arrow-body-style
45
+
46
46
  useEffect(() => {
47
47
  return removeAllGlobalListeners;
48
48
  }, [removeAllGlobalListeners]);
package/src/useId.ts CHANGED
@@ -22,7 +22,7 @@ let canUseDOM = Boolean(
22
22
  window.document.createElement
23
23
  );
24
24
 
25
- let idsUpdaterMap: Map<string, (v: string) => void> = new Map();
25
+ let idsUpdaterMap: Map<string, Array<(v: string) => void>> = new Map();
26
26
 
27
27
  /**
28
28
  * If a default is not provided, generate an id.
@@ -39,7 +39,12 @@ export function useId(defaultId?: string): string {
39
39
  }, []);
40
40
 
41
41
  if (canUseDOM) {
42
- idsUpdaterMap.set(res, updateValue);
42
+ // TS not smart enough to know that `has` means the value exists
43
+ if (idsUpdaterMap.has(res) && !idsUpdaterMap.get(res)!.includes(updateValue)) {
44
+ idsUpdaterMap.set(res, [...idsUpdaterMap.get(res)!, updateValue]);
45
+ } else {
46
+ idsUpdaterMap.set(res, [updateValue]);
47
+ }
43
48
  }
44
49
 
45
50
  useLayoutEffect(() => {
@@ -71,15 +76,15 @@ export function mergeIds(idA: string, idB: string): string {
71
76
  return idA;
72
77
  }
73
78
 
74
- let setIdA = idsUpdaterMap.get(idA);
75
- if (setIdA) {
76
- setIdA(idB);
79
+ let setIdsA = idsUpdaterMap.get(idA);
80
+ if (setIdsA) {
81
+ setIdsA.forEach(fn => fn(idB));
77
82
  return idB;
78
83
  }
79
84
 
80
- let setIdB = idsUpdaterMap.get(idB);
81
- if (setIdB) {
82
- setIdB(idA);
85
+ let setIdsB = idsUpdaterMap.get(idB);
86
+ if (setIdsB) {
87
+ setIdsB.forEach(fn => fn(idA));
83
88
  return idA;
84
89
  }
85
90
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {RefObject, useCallback, useRef} from 'react';
14
14
  import {useEvent} from './useEvent';
15
- // eslint-disable-next-line rulesdir/useLayoutEffectRule
15
+
16
16
  import {useLayoutEffect} from './useLayoutEffect';
17
17
 
18
18
  export interface LoadMoreProps {
@@ -29,7 +29,7 @@ export interface LoadMoreProps {
29
29
  */
30
30
  scrollOffset?: number,
31
31
  /** The data currently loaded. */
32
- items?: any[]
32
+ items?: any
33
33
  }
34
34
 
35
35
  export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | null>) {
@@ -73,7 +73,7 @@ export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | n
73
73
  }
74
74
 
75
75
  lastItems.current = items;
76
- }, [isLoading, onLoadMore, props, ref]);
76
+ }, [isLoading, onLoadMore, props, ref, items]);
77
77
 
78
78
  // TODO: maybe this should still just return scroll props?
79
79
  // Test against case where the ref isn't defined when this is called
@@ -18,7 +18,6 @@ interface ViewportSize {
18
18
  height: number
19
19
  }
20
20
 
21
- // @ts-ignore
22
21
  let visualViewport = typeof document !== 'undefined' && window.visualViewport;
23
22
 
24
23
  export function useViewportSize(): ViewportSize {