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

Function onKeyUp

packages/react-aria/src/interactions/usePress.ts:503–545  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

501 };
502
503 let onKeyUp = (e: KeyboardEvent) => {
504 if (state.isPressed && state.target && isValidKeyboardEvent(e, state.target)) {
505 if (shouldPreventDefaultKeyboard(getEventTarget(e) as Element, e.key)) {
506 e.preventDefault();
507 }
508
509 let target = getEventTarget(e);
510 let wasPressed = nodeContains(state.target, target as Element);
511 // eslint-disable-next-line react-hooks/rules-of-hooks
512 triggerPressEndEvent(createEvent(state.target, e), 'keyboard', wasPressed);
513 if (wasPressed) {
514 triggerSyntheticClick(e, state.target);
515 }
516 removeAllGlobalListeners();
517
518 // If a link was triggered with a key other than Enter, open the URL ourselves.
519 // This means the link has a role override, and the default browser behavior
520 // only applies when using the Enter key.
521 if (
522 e.key !== 'Enter' &&
523 isHTMLAnchorLink(state.target) &&
524 nodeContains(state.target, target as Element) &&
525 !e[LINK_CLICKED]
526 ) {
527 // Store a hidden property on the event so we only trigger link click once,
528 // even if there are multiple usePress instances attached to the element.
529 e[LINK_CLICKED] = true;
530 openLink(state.target, e, false);
531 }
532
533 state.isPressed = false;
534 state.metaKeyEvents?.delete(e.key);
535 } else if (e.key === 'Meta' && state.metaKeyEvents?.size) {
536 // If we recorded keydown events that occurred while the Meta key was pressed,
537 // and those haven't received keyup events already, fire keyup events ourselves.
538 // See comment above for more info about the macOS bug causing this.
539 let events = state.metaKeyEvents;
540 state.metaKeyEvents = undefined;
541 for (let event of events.values()) {
542 state.target?.dispatchEvent(new KeyboardEvent('keyup', event));
543 }
544 }
545 };
546
547 if (typeof PointerEvent !== 'undefined') {
548 pressProps.onPointerDown = e => {

Callers

nothing calls this directly

Calls 8

getEventTargetFunction · 0.90
nodeContainsFunction · 0.90
openLinkFunction · 0.90
isValidKeyboardEventFunction · 0.85
createEventFunction · 0.85
isHTMLAnchorLinkFunction · 0.85
deleteMethod · 0.80

Tested by

no test coverage detected