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

Function onKeyUp

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

Source from the content-addressed store, hash-verified

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