MCPcopy
hub / github.com/adobe/react-spectrum / useFocusable

Function useFocusable

packages/react-aria/src/interactions/useFocusable.tsx:96–129  ·  view source on GitHub ↗
(
  props: FocusableOptions<T>,
  domRef: RefObject<FocusableElement | null>
)

Source from the content-addressed store, hash-verified

94 * Used to make an element focusable and capable of auto focus.
95 */
96export function useFocusable<T extends FocusableElement = FocusableElement>(
97 props: FocusableOptions<T>,
98 domRef: RefObject<FocusableElement | null>
99): FocusableAria {
100 let {focusProps} = useFocus(props);
101 let {keyboardProps} = useKeyboard(props);
102 let interactions = mergeProps(focusProps, keyboardProps);
103 let domProps = useFocusableContext(domRef);
104 let interactionProps = props.isDisabled ? {} : domProps;
105 let autoFocusRef = useRef(props.autoFocus);
106
107 useEffect(() => {
108 if (autoFocusRef.current && domRef.current) {
109 focusSafely(domRef.current);
110 }
111 autoFocusRef.current = false;
112 }, [domRef]);
113
114 // Always set a tabIndex so that Safari allows focusing native buttons and inputs.
115 let tabIndex: number | undefined = props.excludeFromTabOrder ? -1 : 0;
116 if (props.isDisabled) {
117 tabIndex = undefined;
118 }
119
120 return {
121 focusableProps: mergeProps(
122 {
123 ...interactions,
124 tabIndex
125 },
126 interactionProps
127 )
128 };
129}
130
131export interface FocusableComponentProps extends FocusableOptions {
132 children: ReactElement<DOMAttributes, string>;

Callers 14

Pressable.tsxFile · 0.90
useTooltipTriggerFunction · 0.90
useLinkFunction · 0.90
useTableColumnHeaderFunction · 0.90
useMenuItemFunction · 0.90
useSliderThumbFunction · 0.90
useRadioFunction · 0.90
useButtonFunction · 0.90
useTextFieldFunction · 0.90
useToggleFunction · 0.90
useTabFunction · 0.90
useTagFunction · 0.90

Calls 5

useFocusFunction · 0.90
useKeyboardFunction · 0.90
mergePropsFunction · 0.90
focusSafelyFunction · 0.90
useFocusableContextFunction · 0.85

Tested by

no test coverage detected