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

Function onKeyDown

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

Source from the content-addressed store, hash-verified

273 };
274
275 let onKeyDown = (e: ReactKeyboardEvent) => {
276 let activeElement = getActiveElement(getOwnerDocument(ref.current));
277 if (
278 !nodeContains(e.currentTarget, getEventTarget(e) as Element) ||
279 state.isKeyboardNavigationDisabled ||
280 !ref.current ||
281 !activeElement
282 ) {
283 return;
284 }
285
286 if (keyboardNavigationBehavior === 'tab') {
287 if (getEventTarget(e) !== ref.current && e.key !== 'Tab') {
288 e.stopPropagation();
289 return;
290 }
291 }
292
293 switch (e.key) {
294 case 'Tab': {
295 if (keyboardNavigationBehavior === 'tab') {
296 // If there is another focusable element within this item, stop propagation so the tab key
297 // is handled by the browser and not by useSelectableCollection (which would take us out of the list).
298 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
299 walker.currentNode = activeElement;
300 let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
301
302 if (next) {
303 e.stopPropagation();
304 }
305 }
306 }
307 }
308 };
309
310 // Grid cells can have focusable elements inside them. In this case, focus should
311 // 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