@react-aria/focus 3.6.0 → 3.8.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,6 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import {FocusableElement} from '@react-types/shared';
13
14
  import {focusWithoutScrolling, runAfterTransition} from '@react-aria/utils';
14
15
  import {getInteractionModality} from '@react-aria/interactions';
15
16
 
@@ -17,7 +18,7 @@ import {getInteractionModality} from '@react-aria/interactions';
17
18
  * A utility function that focuses an element while avoiding undesired side effects such
18
19
  * as page scrolling and screen reader issues with CSS transitions.
19
20
  */
20
- export function focusSafely(element: HTMLElement) {
21
+ export function focusSafely(element: FocusableElement) {
21
22
  // If the user is interacting with a virtual cursor, e.g. screen reader, then
22
23
  // wait until after any animated transitions that are currently occurring on
23
24
  // the page before shifting focus. This avoids issues with VoiceOver on iOS
package/src/index.ts CHANGED
@@ -10,8 +10,13 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export * from './FocusScope';
14
- export * from './FocusRing';
15
- export * from './useFocusable';
16
- export * from './useFocusRing';
17
- export * from './focusSafely';
13
+ export {FocusScope, useFocusManager, getFocusableTreeWalker, createFocusManager} from './FocusScope';
14
+ export {FocusRing} from './FocusRing';
15
+ export {FocusableProvider, useFocusable} from './useFocusable';
16
+ export {useFocusRing} from './useFocusRing';
17
+ export {focusSafely} from './focusSafely';
18
+
19
+ export type {FocusScopeProps, FocusManager, FocusManagerOptions} from './FocusScope';
20
+ export type {FocusRingProps} from './FocusRing';
21
+ export type {FocusableAria, FocusableOptions, FocusableProviderProps} from './useFocusable';
22
+ export type {AriaFocusRingProps, FocusRingAria} from './useFocusRing';
@@ -1,8 +1,9 @@
1
- import {HTMLAttributes, useCallback, useState} from 'react';
1
+ import {DOMAttributes} from '@react-types/shared';
2
2
  import {isFocusVisible, useFocus, useFocusVisibleListener, useFocusWithin} from '@react-aria/interactions';
3
+ import {useCallback, useState} from 'react';
3
4
  import {useRef} from 'react';
4
5
 
5
- interface FocusRingProps {
6
+ export interface AriaFocusRingProps {
6
7
  /**
7
8
  * Whether to show the focus ring when something
8
9
  * inside the container element has focus (true), or
@@ -18,7 +19,7 @@ interface FocusRingProps {
18
19
  autoFocus?: boolean
19
20
  }
20
21
 
21
- interface FocusRingAria {
22
+ export interface FocusRingAria {
22
23
  /** Whether the element is currently focused. */
23
24
  isFocused: boolean,
24
25
 
@@ -26,7 +27,7 @@ interface FocusRingAria {
26
27
  isFocusVisible: boolean,
27
28
 
28
29
  /** Props to apply to the container element with the focus ring. */
29
- focusProps: HTMLAttributes<HTMLElement>
30
+ focusProps: DOMAttributes
30
31
  }
31
32
 
32
33
  /**
@@ -34,7 +35,7 @@ interface FocusRingAria {
34
35
  * Focus rings are visible only when the user is interacting with a keyboard,
35
36
  * not with a mouse, touch, or other input methods.
36
37
  */
37
- export function useFocusRing(props: FocusRingProps = {}): FocusRingAria {
38
+ export function useFocusRing(props: AriaFocusRingProps = {}): FocusRingAria {
38
39
  let {
39
40
  autoFocus = false,
40
41
  isTextInput,
@@ -10,29 +10,29 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {FocusableDOMProps, FocusableProps} from '@react-types/shared';
13
+ import {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps} from '@react-types/shared';
14
14
  import {focusSafely} from './';
15
15
  import {mergeProps, useSyncRef} from '@react-aria/utils';
16
- import React, {HTMLAttributes, MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
16
+ import React, {MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
17
17
  import {useFocus, useKeyboard} from '@react-aria/interactions';
18
18
 
19
- interface FocusableOptions extends FocusableProps, FocusableDOMProps {
19
+ export interface FocusableOptions extends FocusableProps, FocusableDOMProps {
20
20
  /** Whether focus should be disabled. */
21
21
  isDisabled?: boolean
22
22
  }
23
23
 
24
- interface FocusableProviderProps extends HTMLAttributes<HTMLElement> {
24
+ export interface FocusableProviderProps extends DOMAttributes {
25
25
  /** The child element to provide DOM props to. */
26
26
  children?: ReactNode
27
27
  }
28
28
 
29
29
  interface FocusableContextValue extends FocusableProviderProps {
30
- ref?: MutableRefObject<HTMLElement>
30
+ ref?: MutableRefObject<FocusableElement>
31
31
  }
32
32
 
33
33
  let FocusableContext = React.createContext<FocusableContextValue>(null);
34
34
 
35
- function useFocusableContext(ref: RefObject<HTMLElement>): FocusableContextValue {
35
+ function useFocusableContext(ref: RefObject<FocusableElement>): FocusableContextValue {
36
36
  let context = useContext(FocusableContext) || {};
37
37
  useSyncRef(context, ref);
38
38
 
@@ -44,7 +44,7 @@ function useFocusableContext(ref: RefObject<HTMLElement>): FocusableContextValue
44
44
  /**
45
45
  * Provides DOM props to the nearest focusable child.
46
46
  */
47
- function FocusableProvider(props: FocusableProviderProps, ref: RefObject<HTMLElement>) {
47
+ function FocusableProvider(props: FocusableProviderProps, ref: RefObject<FocusableElement>) {
48
48
  let {children, ...otherProps} = props;
49
49
  let context = {
50
50
  ...otherProps,
@@ -61,15 +61,15 @@ function FocusableProvider(props: FocusableProviderProps, ref: RefObject<HTMLEle
61
61
  let _FocusableProvider = React.forwardRef(FocusableProvider);
62
62
  export {_FocusableProvider as FocusableProvider};
63
63
 
64
- interface FocusableAria {
64
+ export interface FocusableAria {
65
65
  /** Props for the focusable element. */
66
- focusableProps: HTMLAttributes<HTMLElement>
66
+ focusableProps: DOMAttributes
67
67
  }
68
68
 
69
69
  /**
70
70
  * Used to make an element focusable and capable of auto focus.
71
71
  */
72
- export function useFocusable(props: FocusableOptions, domRef: RefObject<HTMLElement>): FocusableAria {
72
+ export function useFocusable(props: FocusableOptions, domRef: RefObject<FocusableElement>): FocusableAria {
73
73
  let {focusProps} = useFocus(props);
74
74
  let {keyboardProps} = useKeyboard(props);
75
75
  let interactions = mergeProps(focusProps, keyboardProps);