@react-aria/focus 3.14.3 → 3.16.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.
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {FocusableElement} from '@react-types/shared';
14
- import {focusWithoutScrolling, runAfterTransition} from '@react-aria/utils';
14
+ import {focusWithoutScrolling, getOwnerDocument, runAfterTransition} from '@react-aria/utils';
15
15
  import {getInteractionModality} from '@react-aria/interactions';
16
16
 
17
17
  /**
@@ -24,11 +24,12 @@ export function focusSafely(element: FocusableElement) {
24
24
  // the page before shifting focus. This avoids issues with VoiceOver on iOS
25
25
  // causing the page to scroll when moving focus if the element is transitioning
26
26
  // from off the screen.
27
+ const ownerDocument = getOwnerDocument(element);
27
28
  if (getInteractionModality() === 'virtual') {
28
- let lastFocusedElement = document.activeElement;
29
+ let lastFocusedElement = ownerDocument.activeElement;
29
30
  runAfterTransition(() => {
30
31
  // If focus did not move and the element is still in the document, focus it.
31
- if (document.activeElement === lastFocusedElement && document.contains(element)) {
32
+ if (ownerDocument.activeElement === lastFocusedElement && element.isConnected) {
32
33
  focusWithoutScrolling(element);
33
34
  }
34
35
  });
@@ -10,8 +10,11 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import {getOwnerWindow} from '@react-aria/utils';
14
+
13
15
  function isStyleVisible(element: Element) {
14
- if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
16
+ const windowObject = getOwnerWindow(element);
17
+ if (!(element instanceof windowObject.HTMLElement) && !(element instanceof windowObject.SVGElement)) {
15
18
  return false;
16
19
  }
17
20
 
@@ -24,7 +27,7 @@ function isStyleVisible(element: Element) {
24
27
  );
25
28
 
26
29
  if (isVisible) {
27
- const {getComputedStyle} = element.ownerDocument.defaultView;
30
+ const {getComputedStyle} = element.ownerDocument.defaultView as unknown as Window;
28
31
  let {display: computedDisplay, visibility: computedVisibility} = getComputedStyle(element);
29
32
 
30
33
  isVisible = (
@@ -49,11 +52,11 @@ function isAttributeVisible(element: Element, childElement?: Element) {
49
52
  }
50
53
 
51
54
  /**
52
- * Adapted from https://github.com/testing-library/jest-dom and
55
+ * Adapted from https://github.com/testing-library/jest-dom and
53
56
  * https://github.com/vuejs/vue-test-utils-next/.
54
57
  * Licensed under the MIT License.
55
58
  * @param element - Element to evaluate for display or visibility.
56
- */
59
+ */
57
60
  export function isElementVisible(element: Element, childElement?: Element) {
58
61
  return (
59
62
  element.nodeName !== '#comment' &&
@@ -12,8 +12,8 @@
12
12
 
13
13
  import {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps} from '@react-types/shared';
14
14
  import {focusSafely} from './';
15
- import {mergeProps, useSyncRef} from '@react-aria/utils';
16
- import React, {MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
15
+ import {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';
16
+ import React, {ForwardedRef, MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
17
17
  import {useFocus, useKeyboard} from '@react-aria/interactions';
18
18
 
19
19
  export interface FocusableOptions extends FocusableProps, FocusableDOMProps {
@@ -30,7 +30,7 @@ interface FocusableContextValue extends FocusableProviderProps {
30
30
  ref?: MutableRefObject<FocusableElement>
31
31
  }
32
32
 
33
- let FocusableContext = React.createContext<FocusableContextValue>(null);
33
+ let FocusableContext = React.createContext<FocusableContextValue | null>(null);
34
34
 
35
35
  function useFocusableContext(ref: RefObject<FocusableElement>): FocusableContextValue {
36
36
  let context = useContext(FocusableContext) || {};
@@ -44,11 +44,12 @@ function useFocusableContext(ref: RefObject<FocusableElement>): FocusableContext
44
44
  /**
45
45
  * Provides DOM props to the nearest focusable child.
46
46
  */
47
- function FocusableProvider(props: FocusableProviderProps, ref: RefObject<FocusableElement>) {
47
+ function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {
48
48
  let {children, ...otherProps} = props;
49
+ let objRef = useObjectRef(ref);
49
50
  let context = {
50
51
  ...otherProps,
51
- ref
52
+ ref: objRef
52
53
  };
53
54
 
54
55
  return (