@react-aria/utils 3.21.1 → 3.23.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.
@@ -10,19 +10,25 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export function getScrollParent(node: Element): Element {
14
- if (isScrollable(node)) {
13
+ export function getScrollParent(node: Element, checkForOverflow?: boolean): Element {
14
+ if (isScrollable(node, checkForOverflow)) {
15
15
  node = node.parentElement;
16
16
  }
17
17
 
18
- while (node && !isScrollable(node)) {
18
+ while (node && !isScrollable(node, checkForOverflow)) {
19
19
  node = node.parentElement;
20
20
  }
21
21
 
22
22
  return node || document.scrollingElement || document.documentElement;
23
23
  }
24
24
 
25
- export function isScrollable(node: Element): boolean {
25
+ export function isScrollable(node: Element, checkForOverflow?: boolean): boolean {
26
26
  let style = window.getComputedStyle(node);
27
- return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
27
+ let isScrollable = /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
28
+
29
+ if (isScrollable && checkForOverflow) {
30
+ isScrollable = node.scrollHeight !== node.clientHeight || node.scrollWidth !== node.clientWidth;
31
+ }
32
+
33
+ return isScrollable;
28
34
  }
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  */
12
12
  export {useId, mergeIds, useSlotId} from './useId';
13
13
  export {chain} from './chain';
14
+ export {getOwnerDocument, getOwnerWindow} from './domHelpers';
14
15
  export {mergeProps} from './mergeProps';
15
16
  export {mergeRefs} from './mergeRefs';
16
17
  export {filterDOMProps} from './filterDOMProps';
@@ -29,7 +30,7 @@ export {useSyncRef} from './useSyncRef';
29
30
  export {getScrollParent, isScrollable} from './getScrollParent';
30
31
  export {useViewportSize} from './useViewportSize';
31
32
  export {useDescription} from './useDescription';
32
- export {isMac, isIPhone, isIPad, isIOS, isAppleDevice, isWebKit, isChrome, isAndroid} from './platform';
33
+ export {isMac, isIPhone, isIPad, isIOS, isAppleDevice, isWebKit, isChrome, isAndroid, isFirefox} from './platform';
33
34
  export {useEvent} from './useEvent';
34
35
  export {useValueEffect} from './useValueEffect';
35
36
  export {scrollIntoView, scrollIntoViewport} from './scrollIntoView';
@@ -17,7 +17,7 @@ import {useState} from 'react';
17
17
  let descriptionId = 0;
18
18
  const descriptionNodes = new Map<string, {refCount: number, element: Element}>();
19
19
 
20
- export function useDescription(description: string): AriaLabelingProps {
20
+ export function useDescription(description?: string): AriaLabelingProps {
21
21
  let [id, setId] = useState(undefined);
22
22
 
23
23
  useLayoutEffect(() => {
@@ -13,13 +13,14 @@
13
13
  import {useCallback, useRef} from 'react';
14
14
  import {useLayoutEffect} from './useLayoutEffect';
15
15
 
16
- export function useEffectEvent(fn) {
17
- const ref = useRef(null);
16
+ export function useEffectEvent<T extends Function>(fn: T): T {
17
+ const ref = useRef<T | null>(null);
18
18
  useLayoutEffect(() => {
19
19
  ref.current = fn;
20
20
  }, [fn]);
21
- return useCallback((...args) => {
22
- const f = ref.current;
21
+ // @ts-ignore
22
+ return useCallback<T>((...args) => {
23
+ const f = ref.current!;
23
24
  return f(...args);
24
25
  }, []);
25
26
  }
package/src/useEvent.ts CHANGED
@@ -16,7 +16,7 @@ import {useEffectEvent} from './useEffectEvent';
16
16
  export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
17
17
  ref: RefObject<EventTarget>,
18
18
  event: K,
19
- handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
19
+ handler?: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
20
20
  options?: boolean | AddEventListenerOptions
21
21
  ) {
22
22
  let handleEvent = useEffectEvent(handler);
package/src/useId.ts CHANGED
@@ -15,6 +15,13 @@ import {useLayoutEffect} from './useLayoutEffect';
15
15
  import {useSSRSafeId} from '@react-aria/ssr';
16
16
  import {useValueEffect} from './';
17
17
 
18
+ // copied from SSRProvider.tsx to reduce exports, if needed again, consider sharing
19
+ let canUseDOM = Boolean(
20
+ typeof window !== 'undefined' &&
21
+ window.document &&
22
+ window.document.createElement
23
+ );
24
+
18
25
  let idsUpdaterMap: Map<string, (v: string) => void> = new Map();
19
26
 
20
27
  /**
@@ -31,7 +38,9 @@ export function useId(defaultId?: string): string {
31
38
  nextId.current = val;
32
39
  }, []);
33
40
 
34
- idsUpdaterMap.set(res, updateValue);
41
+ if (canUseDOM) {
42
+ idsUpdaterMap.set(res, updateValue);
43
+ }
35
44
 
36
45
  useLayoutEffect(() => {
37
46
  let r = res;
package/src/useSyncRef.ts CHANGED
@@ -18,7 +18,7 @@ interface ContextValue<T> {
18
18
  }
19
19
 
20
20
  // Syncs ref from context with ref passed to hook
21
- export function useSyncRef<T>(context: ContextValue<T>, ref: RefObject<T>) {
21
+ export function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T>) {
22
22
  useLayoutEffect(() => {
23
23
  if (context && context.ref && ref) {
24
24
  context.ref.current = ref.current;