MCPcopy Create free account
hub / github.com/adobe/react-spectrum / tab

Function tab

packages/react-aria/src/selection/useSelectableCollection.ts:375–403  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

373 };
374
375 let tab = () => {
376 if (!allowsTabNavigation && ref.current) {
377 // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
378 // However, collections should be treated as a single tab stop, with arrow key navigation internally.
379 // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
380 // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
381 // in the collection, so that the browser default behavior will apply starting from that element
382 // rather than the currently focused one.
383
384 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
385 let next: FocusableElement | undefined = undefined;
386 let last: FocusableElement;
387 do {
388 last = walker.lastChild() as FocusableElement;
389 if (last) {
390 next = last;
391 }
392 } while (last);
393
394 // If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to
395 // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between
396 // focusing the containing cell and back to the non-tabbable child element
397 let activeElement = getActiveElement();
398 if (next && (!isFocusWithin(next) || (activeElement && !isTabbable(activeElement)))) {
399 focusWithoutScrolling(next);
400 }
401 }
402 return {shouldContinuePropagation: true, shouldPreventDefault: false};
403 };
404
405 let shiftTab = () => {
406 if (!allowsTabNavigation && ref.current) {

Callers

nothing calls this directly

Calls 6

getFocusableTreeWalkerFunction · 0.90
getActiveElementFunction · 0.90
isFocusWithinFunction · 0.90
isTabbableFunction · 0.90
focusWithoutScrollingFunction · 0.90
lastChildMethod · 0.45

Tested by

no test coverage detected