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

Function onKeyDown

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

Source from the content-addressed store, hash-verified

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