|
10 | 10 | * governing permissions and limitations under the License. |
11 | 11 | */ |
12 | 12 |
|
13 | | -import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, isTabbable, mergeProps, nodeContains, scrollIntoView, scrollIntoViewport, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils'; |
| 13 | +import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, isFocusWithin, isTabbable, mergeProps, nodeContains, scrollIntoView, scrollIntoViewport, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils'; |
14 | 14 | import {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus'; |
15 | 15 | import {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared'; |
16 | 16 | import {flushSync} from 'react-dom'; |
@@ -315,7 +315,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions |
315 | 315 | // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between |
316 | 316 | // focusing the containing cell and back to the non-tabbable child element |
317 | 317 | let activeElement = getActiveElement(); |
318 | | - if (next && (!nodeContains(next, activeElement) || (activeElement && !isTabbable(activeElement)))) { |
| 318 | + if (next && (!isFocusWithin(next) || (activeElement && !isTabbable(activeElement)))) { |
319 | 319 | focusWithoutScrolling(next); |
320 | 320 | } |
321 | 321 | } |
@@ -380,7 +380,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions |
380 | 380 | let element = getItemElement(ref, manager.focusedKey); |
381 | 381 | if (element instanceof HTMLElement) { |
382 | 382 | // This prevents a flash of focus on the first/last element in the collection, or the collection itself. |
383 | | - if (!nodeContains(element, getActiveElement()) && !shouldUseVirtualFocus) { |
| 383 | + if (!isFocusWithin(element) && !shouldUseVirtualFocus) { |
384 | 384 | focusWithoutScrolling(element); |
385 | 385 | } |
386 | 386 |
|
|
0 commit comments