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

Function onClick

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

Source from the content-addressed store, hash-verified

447 }
448 },
449 onClick(e) {
450 if (e && !nodeContains(e.currentTarget, getEventTarget(e))) {
451 return;
452 }
453
454 if (e && e.button === 0 && !state.isTriggeringEvent && !(openLink as any).isOpening) {
455 let shouldStopPropagation = true;
456 if (isDisabled) {
457 e.preventDefault();
458 }
459
460 // If triggered from a screen reader or by using element.click(),
461 // trigger as if it were a keyboard click.
462 if (
463 !state.ignoreEmulatedMouseEvents &&
464 !state.isPressed &&
465 (state.pointerType === 'virtual' || isVirtualClick(e.nativeEvent))
466 ) {
467 let stopPressStart = triggerPressStart(e, 'virtual');
468 let stopPressUp = triggerPressUpEvent(e, 'virtual');
469 let stopPressEnd = triggerPressEndEvent(e, 'virtual');
470 triggerClick(e);
471 shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;
472 } else if (state.isPressed && state.pointerType !== 'keyboard') {
473 let pointerType =
474 state.pointerType ||
475 ((e.nativeEvent as PointerEvent).pointerType as PointerType) ||
476 'virtual';
477 let stopPressUp = triggerPressUpEvent(createEvent(e.currentTarget, e), pointerType);
478 let stopPressEnd = triggerPressEndEvent(
479 createEvent(e.currentTarget, e),
480 pointerType,
481 true
482 );
483 shouldStopPropagation = stopPressUp && stopPressEnd;
484 state.isOverTarget = false;
485 triggerClick(e);
486 // oxlint-disable-next-line react/react-compiler
487 cancelEvent(e);
488 }
489
490 state.ignoreEmulatedMouseEvents = false;
491 if (shouldStopPropagation) {
492 e.stopPropagation();
493 }
494 }
495 }
496 };
497
498 let onKeyUp = (e: KeyboardEvent) => {

Callers 1

usePressFunction · 0.70

Calls 4

nodeContainsFunction · 0.90
getEventTargetFunction · 0.90
isVirtualClickFunction · 0.90
createEventFunction · 0.85

Tested by

no test coverage detected