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

Function onTouchEnd

packages/react-aria/src/combobox/useComboBox.ts:368–393  ·  view source on GitHub ↗
(e: TouchEvent)

Source from the content-addressed store, hash-verified

366 // If a touch happens on direct center of ComboBox input, might be virtual click from iPad so open ComboBox menu
367 let lastEventTime = useRef(0);
368 let onTouchEnd = (e: TouchEvent) => {
369 if (isDisabled || isReadOnly) {
370 return;
371 }
372
373 // Sometimes VoiceOver on iOS fires two touchend events in quick succession. Ignore the second one.
374 if (e.timeStamp - lastEventTime.current < 500) {
375 e.preventDefault();
376 inputRef.current?.focus();
377 return;
378 }
379
380 let rect = (getEventTarget(e) as Element).getBoundingClientRect();
381 let touch = e.changedTouches[0];
382
383 let centerX = Math.ceil(rect.left + 0.5 * rect.width);
384 let centerY = Math.ceil(rect.top + 0.5 * rect.height);
385
386 if (touch.clientX === centerX && touch.clientY === centerY) {
387 e.preventDefault();
388 inputRef.current?.focus();
389 state.toggle(null, 'manual');
390
391 lastEventTime.current = e.timeStamp;
392 }
393 };
394
395 // VoiceOver has issues with announcing aria-activedescendant properly on change
396 // (especially on iOS). We use a live region announcer to announce focus changes

Callers

nothing calls this directly

Calls 3

getEventTargetFunction · 0.90
focusMethod · 0.80
toggleMethod · 0.65

Tested by

no test coverage detected