()
| 112 | // Handles focusing the cell. If there is a focusable child, |
| 113 | // it is focused, otherwise the cell itself is focused. |
| 114 | let focus = () => { |
| 115 | if (ref.current) { |
| 116 | let treeWalker = getFocusableTreeWalker(ref.current); |
| 117 | if (focusMode === 'child') { |
| 118 | let activeElement = getActiveElement(getOwnerDocument(ref.current)); |
| 119 | |
| 120 | // If focus is already on a focusable child within the cell, early return so we don't shift focus |
| 121 | if (isFocusWithin(ref.current) && ref.current !== activeElement) { |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | let ownerDocument = getOwnerDocument(ref.current); |
| 126 | let shouldRestoreToLastFocused = |
| 127 | !activeElement || activeElement === ownerDocument.body || activeElement === ref.current; |
| 128 | if (shouldRestoreToLastFocused) { |
| 129 | let lastChild = lastFocusedChild.current; |
| 130 | if ( |
| 131 | lastChild && |
| 132 | keyWhenFocused.current === node.key && |
| 133 | nodeContains(ref.current, lastChild) |
| 134 | ) { |
| 135 | focusSafely(lastChild); |
| 136 | return; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | let focusable = |
| 141 | state.selectionManager.childFocusStrategy === 'last' |
| 142 | ? last(treeWalker) |
| 143 | : (treeWalker.firstChild() as FocusableElement); |
| 144 | if (focusable) { |
| 145 | focusSafely(focusable); |
| 146 | return; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if ( |
| 151 | (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) || |
| 152 | !isFocusWithin(ref.current) |
| 153 | ) { |
| 154 | focusSafely(ref.current); |
| 155 | } |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | let {itemProps, isPressed} = useSelectableItem({ |
| 160 | selectionManager: state.selectionManager, |
no test coverage detected