(e: FocusEvent)
| 327 | // Grid cells can have focusable elements inside them. In this case, focus should |
| 328 | // be marshalled to that element rather than focusing the cell itself. |
| 329 | let onFocus = (e: FocusEvent) => { |
| 330 | keyWhenFocused.current = node.key; |
| 331 | if (getEventTarget(e) !== ref.current) { |
| 332 | // useSelectableItem only handles setting the focused key when |
| 333 | // the focused element is the gridcell itself. We also want to |
| 334 | // set the focused key when a child element receives focus. |
| 335 | // If focus is currently visible (e.g. the user is navigating with the keyboard), |
| 336 | // then skip this. We want to restore focus to the previously focused row/cell |
| 337 | // in that case since the table should act like a single tab stop. |
| 338 | |
| 339 | let target = getEventTarget(e) as FocusableElement; |
| 340 | if (ref.current && nodeContains(ref.current, target)) { |
| 341 | lastFocusedChild.current = target; |
| 342 | } |
| 343 | |
| 344 | if (!isFocusVisible()) { |
| 345 | state.selectionManager.setFocusedKey(node.key); |
| 346 | } |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child |
| 351 | // since that would be a focus trap |
| 352 | if ( |
| 353 | focusMode === 'child' && |
| 354 | e.relatedTarget && |
| 355 | nodeContains(ref.current, e.relatedTarget as Element) |
| 356 | ) { |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | // If the cell itself is focused, wait a frame so that focus finishes propagating |
| 361 | // up to the tree, and move focus to a focusable child if possible. |
| 362 | requestAnimationFrame(() => { |
| 363 | if ( |
| 364 | focusMode === 'child' && |
| 365 | getActiveElement(getOwnerDocument(ref.current)) === ref.current |
| 366 | ) { |
| 367 | focus(); |
| 368 | } |
| 369 | }); |
| 370 | }; |
| 371 | |
| 372 | // oxlint-disable-next-line react/react-compiler |
| 373 | let gridCellProps: DOMAttributes = mergeProps(itemProps, { |
nothing calls this directly
no test coverage detected