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

Function onFocus

packages/react-aria/src/gridlist/useGridListItem.ts:314–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312 };
313
314 let onFocus = e => {
315 keyWhenFocused.current = node.key;
316 if (getEventTarget(e) !== ref.current) {
317 // useSelectableItem only handles setting the focused key when
318 // the focused element is the row itself. We also want to
319 // set the focused key when a child element receives focus.
320 // If focus is currently visible (e.g. the user is navigating with the keyboard),
321 // then skip this. We want to restore focus to the previously focused row
322 // in that case since the list should act like a single tab stop.
323 if (!isFocusVisible()) {
324 state.selectionManager.setFocusedKey(node.key);
325 }
326 return;
327 }
328
329 // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child
330 // since that would be a focus trap
331 if (
332 focusMode === 'child' &&
333 e.relatedTarget &&
334 nodeContains(ref.current, e.relatedTarget as Element)
335 ) {
336 return;
337 }
338
339 // If the cell itself is focused, wait a frame so that focus finishes propagating
340 // up to the tree, and move focus to a focusable child if possible.
341 requestAnimationFrame(() => {
342 if (
343 focusMode === 'child' &&
344 getActiveElement(getOwnerDocument(ref.current)) === ref.current
345 ) {
346 focus();
347 }
348 });
349 };
350
351 let onKeyDown = (e: ReactKeyboardEvent) => {
352 let activeElement = getActiveElement(getOwnerDocument(ref.current));

Callers

nothing calls this directly

Calls 7

getEventTargetFunction · 0.90
isFocusVisibleFunction · 0.90
nodeContainsFunction · 0.90
getActiveElementFunction · 0.90
getOwnerDocumentFunction · 0.90
focusFunction · 0.70
setFocusedKeyMethod · 0.65

Tested by

no test coverage detected