MCPcopy Create free account
hub / github.com/adobe/react-spectrum / focus

Function focus

packages/react-aria/src/grid/useGridCell.ts:111–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

109 // Handles focusing the cell. If there is a focusable child,
110 // it is focused, otherwise the cell itself is focused.
111 let focus = () => {
112 if (ref.current) {
113 let treeWalker = getFocusableTreeWalker(ref.current);
114 if (focusMode === 'child') {
115 // If focus is already on a focusable child within the cell, early return so we don't shift focus
116 if (
117 isFocusWithin(ref.current) &&
118 ref.current !== getActiveElement(getOwnerDocument(ref.current))
119 ) {
120 return;
121 }
122
123 let focusable =
124 state.selectionManager.childFocusStrategy === 'last'
125 ? last(treeWalker)
126 : (treeWalker.firstChild() as FocusableElement);
127 if (focusable) {
128 focusSafely(focusable);
129 return;
130 }
131 }
132
133 if (
134 (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||
135 !isFocusWithin(ref.current)
136 ) {
137 focusSafely(ref.current);
138 }
139 }
140 };
141
142 let {itemProps, isPressed} = useSelectableItem({
143 selectionManager: state.selectionManager,

Callers 3

onFocusFunction · 0.70
useSelectableItemFunction · 0.50
useFormValidationFunction · 0.50

Calls 7

getFocusableTreeWalkerFunction · 0.90
isFocusWithinFunction · 0.90
getActiveElementFunction · 0.90
getOwnerDocumentFunction · 0.90
focusSafelyFunction · 0.90
lastFunction · 0.70
firstChildMethod · 0.45

Tested by

no test coverage detected