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