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

Function onKeyUp

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

Source from the content-addressed store, hash-verified

511 };
512
513 let onKeyUp = (e: KeyboardEvent) => {
514 if (state.isPressed && state.target && isValidKeyboardEvent(e, state.target)) {
515 if (shouldPreventDefaultKeyboard(getEventTarget(e) as Element, e)) {
516 e.preventDefault();
517 }
518 let target = getEventTarget(e);
519 let wasPressed = nodeContains(state.target, target as Element);
520
521 // Space performs the element's activation behavior on key up. This listener is capturing,
522 // so another handler may still prevent the default behavior. Store the event and read
523 // defaultPrevented later, once it has finished propagating. Only store it if the key
524 // was released on the pressed target, where the browser can fire its click.
525 state.defaultKeyboardClickEvent = e.key !== 'Enter' && wasPressed ? e : null;
526
527 triggerPressEndEvent(createEvent(state.target, e), 'keyboard', wasPressed);
528 if (wasPressed) {
529 triggerSyntheticClick(e, state.target);
530 }
531 removeAllGlobalListeners();
532
533 // If a link was triggered with a key other than Enter, open the URL ourselves.
534 // This means the link has a role override, and the default browser behavior
535 // only applies when using the Enter key.
536 if (
537 e.key !== 'Enter' &&
538 isHTMLAnchorLink(state.target) &&
539 nodeContains(state.target, target as Element) &&
540 !e[LINK_CLICKED]
541 ) {
542 // Store a hidden property on the event so we only trigger link click once,
543 // even if there are multiple usePress instances attached to the element.
544 e[LINK_CLICKED] = true;
545 openLink(state.target, e, false);
546 }
547
548 state.isPressed = false;
549 state.metaKeyEvents?.delete(e.key);
550 } else if (e.key === 'Meta' && state.metaKeyEvents?.size) {
551 // If we recorded keydown events that occurred while the Meta key was pressed,
552 // and those haven't received keyup events already, fire keyup events ourselves.
553 // See comment above for more info about the macOS bug causing this.
554 let events = state.metaKeyEvents;
555 state.metaKeyEvents = undefined;
556 for (let event of events.values()) {
557 state.target?.dispatchEvent(new KeyboardEvent('keyup', event));
558 }
559 }
560 };
561
562 if (typeof PointerEvent !== 'undefined') {
563 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