()
| 113 | // focus to go to the item when the DOM node is reused for a different item in a virtualizer. |
| 114 | let keyWhenFocused = useRef<Key | null>(null); |
| 115 | let focus = () => { |
| 116 | if (ref.current === null) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | if (focusMode === 'child') { |
| 121 | // If focus is already on a focusable child within the row, early return so we don't shift focus |
| 122 | if ( |
| 123 | isFocusWithin(ref.current) && |
| 124 | ref.current !== getActiveElement(getOwnerDocument(ref.current)) |
| 125 | ) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | let treeWalker = getFocusableTreeWalker(ref.current, {tabbable: true}); |
| 130 | let focusable = treeWalker.firstChild() as FocusableElement; |
| 131 | if (focusable) { |
| 132 | focusSafely(focusable); |
| 133 | scrollIntoViewport(focusable, {containingElement: getScrollParent(focusable)}); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Don't shift focus to the row if the active element is a element within the row already |
| 139 | // (e.g. clicking on a row button) |
| 140 | if ( |
| 141 | (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) || |
| 142 | !isFocusWithin(ref.current) |
| 143 | ) { |
| 144 | focusSafely(ref.current); |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | let treeGridRowProps: HTMLAttributes<HTMLElement> = {}; |
| 149 | let hasChildRows = props.hasChildItems; |
no test coverage detected