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

Function onKeyDown

packages/react-aria/src/gridlist/useGridListItem.ts:351–401  ·  view source on GitHub ↗
(e: ReactKeyboardEvent)

Source from the content-addressed store, hash-verified

349 };
350
351 let onKeyDown = (e: ReactKeyboardEvent) => {
352 let activeElement = getActiveElement(getOwnerDocument(ref.current));
353 if (
354 !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||
355 !ref.current ||
356 !activeElement
357 ) {
358 return;
359 }
360
361 if (keyboardNavigationBehavior === 'tab') {
362 // Stop propagation for all events that originate from the children of the gridlist item since we don't want to trigger
363 // grid level interactions (row navigation/typeselect/etc)
364 // exception made for Tab since that needs to propagate to useSelectableCollection to tab out of the gridlist, might be others?
365 if (getEventTarget(e) !== ref.current && e.key !== 'Tab') {
366 e.stopPropagation();
367 return;
368 }
369
370 if (
371 handleTreeExpansionKeys(
372 e,
373 state,
374 node,
375 hasChildRows,
376 direction,
377 activeElement,
378 ref.current,
379 allowsArrowNavigation
380 )
381 ) {
382 return;
383 }
384 }
385
386 switch (e.key) {
387 case 'Tab': {
388 if (keyboardNavigationBehavior === 'tab') {
389 // If there is another focusable element within this item, stop propagation so the tab key
390 // is handled by the browser and not by useSelectableCollection (which would take us out of the list).
391 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
392 walker.currentNode = activeElement;
393 let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
394
395 if (next) {
396 e.stopPropagation();
397 }
398 }
399 }
400 }
401 };
402
403 let syntheticLinkProps = useSyntheticLinkProps(node.props);
404 let linkProps = itemStates.hasAction ? syntheticLinkProps : {};

Callers 1

useGridListItemFunction · 0.70

Calls 8

getActiveElementFunction · 0.90
getOwnerDocumentFunction · 0.90
nodeContainsFunction · 0.90
getEventTargetFunction · 0.90
getFocusableTreeWalkerFunction · 0.90
handleTreeExpansionKeysFunction · 0.85
previousNodeMethod · 0.80
nextNodeMethod · 0.80

Tested by

no test coverage detected