@react-aria/focus 3.5.5 → 3.7.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.
- package/dist/main.js +69 -78
- package/dist/main.js.map +1 -1
- package/dist/module.js +59 -60
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +26 -24
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/FocusRing.tsx +1 -1
- package/src/FocusScope.tsx +93 -66
- package/src/focusSafely.ts +2 -1
- package/src/index.ts +10 -5
- package/src/useFocusRing.ts +14 -13
- package/src/useFocusable.tsx +10 -10
package/src/useFocusRing.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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:
|
|
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:
|
|
38
|
+
export function useFocusRing(props: AriaFocusRingProps = {}): FocusRingAria {
|
|
38
39
|
let {
|
|
39
40
|
autoFocus = false,
|
|
40
41
|
isTextInput,
|
|
@@ -43,20 +44,20 @@ export function useFocusRing(props: FocusRingProps = {}): FocusRingAria {
|
|
|
43
44
|
let state = useRef({
|
|
44
45
|
isFocused: false,
|
|
45
46
|
isFocusVisible: autoFocus || isFocusVisible()
|
|
46
|
-
})
|
|
47
|
+
});
|
|
47
48
|
let [isFocused, setFocused] = useState(false);
|
|
48
|
-
let [isFocusVisibleState, setFocusVisible] = useState(() => state.isFocused && state.isFocusVisible);
|
|
49
|
+
let [isFocusVisibleState, setFocusVisible] = useState(() => state.current.isFocused && state.current.isFocusVisible);
|
|
49
50
|
|
|
50
|
-
let updateState = () => setFocusVisible(state.isFocused && state.isFocusVisible);
|
|
51
|
+
let updateState = useCallback(() => setFocusVisible(state.current.isFocused && state.current.isFocusVisible), []);
|
|
51
52
|
|
|
52
|
-
let onFocusChange = isFocused => {
|
|
53
|
-
state.isFocused = isFocused;
|
|
53
|
+
let onFocusChange = useCallback(isFocused => {
|
|
54
|
+
state.current.isFocused = isFocused;
|
|
54
55
|
setFocused(isFocused);
|
|
55
56
|
updateState();
|
|
56
|
-
};
|
|
57
|
+
}, [updateState]);
|
|
57
58
|
|
|
58
59
|
useFocusVisibleListener((isFocusVisible) => {
|
|
59
|
-
state.isFocusVisible = isFocusVisible;
|
|
60
|
+
state.current.isFocusVisible = isFocusVisible;
|
|
60
61
|
updateState();
|
|
61
62
|
}, [], {isTextInput});
|
|
62
63
|
|
|
@@ -72,7 +73,7 @@ export function useFocusRing(props: FocusRingProps = {}): FocusRingAria {
|
|
|
72
73
|
|
|
73
74
|
return {
|
|
74
75
|
isFocused,
|
|
75
|
-
isFocusVisible: state.isFocused && isFocusVisibleState,
|
|
76
|
+
isFocusVisible: state.current.isFocused && isFocusVisibleState,
|
|
76
77
|
focusProps: within ? focusWithinProps : focusProps
|
|
77
78
|
};
|
|
78
79
|
}
|
package/src/useFocusable.tsx
CHANGED
|
@@ -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, {
|
|
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
|
|
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<
|
|
30
|
+
ref?: MutableRefObject<FocusableElement>
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
let FocusableContext = React.createContext<FocusableContextValue>(null);
|
|
34
34
|
|
|
35
|
-
function useFocusableContext(ref: RefObject<
|
|
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<
|
|
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:
|
|
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<
|
|
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);
|