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

Function onFocus

packages/react-aria/src/grid/useGridCell.ts:257–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255 // Grid cells can have focusable elements inside them. In this case, focus should
256 // be marshalled to that element rather than focusing the cell itself.
257 let onFocus = e => {
258 keyWhenFocused.current = node.key;
259 if (getEventTarget(e) !== ref.current) {
260 // useSelectableItem only handles setting the focused key when
261 // the focused element is the gridcell itself. We also want to
262 // set the focused key when a child element receives focus.
263 // If focus is currently visible (e.g. the user is navigating with the keyboard),
264 // then skip this. We want to restore focus to the previously focused row/cell
265 // in that case since the table should act like a single tab stop.
266 if (!isFocusVisible()) {
267 state.selectionManager.setFocusedKey(node.key);
268 }
269 return;
270 }
271
272 // If the cell itself is focused, wait a frame so that focus finishes propagatating
273 // up to the tree, and move focus to a focusable child if possible.
274 requestAnimationFrame(() => {
275 if (focusMode === 'child' && getActiveElement() === ref.current) {
276 focus();
277 }
278 });
279 };
280
281 let gridCellProps: DOMAttributes = mergeProps(itemProps, {
282 role: 'gridcell',

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected