()
| 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, |
no test coverage detected