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

Function onKeyDown

packages/react-aria/src/grid/useGridCell.ts:293–326  ·  view source on GitHub ↗
(e: ReactKeyboardEvent)

Source from the content-addressed store, hash-verified

291 };
292
293 let onKeyDown = (e: ReactKeyboardEvent) => {
294 let activeElement = getActiveElement(getOwnerDocument(ref.current));
295 if (
296 !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||
297 state.isKeyboardNavigationDisabled ||
298 !ref.current ||
299 !activeElement
300 ) {
301 return;
302 }
303
304 if (keyboardNavigationBehavior === 'tab') {
305 if (getEventTarget(e) !== ref.current && e.key !== 'Tab') {
306 e.stopPropagation();
307 return;
308 }
309 }
310
311 switch (e.key) {
312 case 'Tab': {
313 if (keyboardNavigationBehavior === 'tab') {
314 // If there is another focusable element within this item, stop propagation so the tab key
315 // is handled by the browser and not by useSelectableCollection (which would take us out of the list).
316 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
317 walker.currentNode = activeElement;
318 let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
319
320 if (next) {
321 e.stopPropagation();
322 }
323 }
324 }
325 }
326 };
327
328 // Grid cells can have focusable elements inside them. In this case, focus should
329 // be marshalled to that element rather than focusing the cell itself.

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected