Skip to content

Commit 1035f7d

Browse files
committed
Improve the cross-browser consistency of useExtendedTouchActive
1 parent a700b20 commit 1035f7d

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ Default value: `false`
392392

393393
By default React Interactive only stays in the `touchActive` state while a `click` event (from the touch interaction) is still possible. To remain in the `touchActive` state for as long as the touch point is on the screen, pass in the `useExtendedTouchActive` prop. This can be useful for implementing functionality such as show on `touchActive`, long press, etc.
394394

395+
Note that anchor tags, `<a>`, on touch devices have their own device/browser specific behavior for long press (context/callout menu, dragging, etc). If you need to disable the native behavior for long press of links you can:
396+
- Set a `onContextMenu` event listener and call `preventDefault()`, to prevent the context menu from appearing.
397+
- Set `-webkit-touch-callout: none` style to prevent the iOS "context menu" from appearing (iOS doesn't support `contextmenu` events).
398+
- Set `draggable="false"` on the `<a>` element (by passing it in as a prop).
399+
395400
---
396401

397402
### `ref`: object `ref` | callback `ref`

src/index.tsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -617,26 +617,8 @@ const InteractiveNotMemoized: PolymorphicForwardRefExoticComponent<
617617

618618
////////////////////////////////////
619619

620-
// prevent the context menu from popping up on long touch when useExtendedTouchActive is true
621-
const { onContextMenu } = restProps;
622-
const handleContextMenuEvent = React.useCallback(
623-
(e: React.MouseEvent) => {
624-
if (inTouchActiveState && useExtendedTouchActive) {
625-
e.preventDefault();
626-
}
627-
if (onContextMenu) {
628-
(onContextMenu as React.MouseEventHandler)(e);
629-
}
630-
},
631-
[inTouchActiveState, useExtendedTouchActive, onContextMenu],
632-
);
633-
634-
////////////////////////////////////
635-
636620
// create object with event listeners to pass to <As {...eventListeners}>
637-
const eventListeners: Record<string, React.ReactEventHandler> = {
638-
onContextMenu: handleContextMenuEvent,
639-
};
621+
const eventListeners: Record<string, React.ReactEventHandler> = {};
640622
eventListenerPropNames.forEach((listenerPropName) => {
641623
eventListeners[listenerPropName] = handleEvent;
642624
});
@@ -705,11 +687,6 @@ const InteractiveNotMemoized: PolymorphicForwardRefExoticComponent<
705687
) {
706688
style.cursor = 'pointer';
707689
}
708-
if (inTouchActiveState && useExtendedTouchActive) {
709-
// set webkit-touch-callout: none to prevent the iOS "context menu" from popping up on long touch
710-
// note that iOS doesn't fire contextmenu events so need to set webkit-touch-callout
711-
style.WebkitTouchCallout = 'none';
712-
}
713690

714691
// add style prop passed to RI
715692
Object.assign(style, restProps.style);
@@ -812,11 +789,6 @@ const InteractiveNotMemoized: PolymorphicForwardRefExoticComponent<
812789

813790
return (
814791
<As
815-
// if useExtendedTouchActive then prevent long touch from dragging links
816-
// allow draggable to be overridden by passed in draggable prop from restProps
817-
draggable={
818-
inTouchActiveState && useExtendedTouchActive ? false : undefined
819-
}
820792
{...restProps}
821793
{...eventListeners}
822794
{...disabledProps}

0 commit comments

Comments
 (0)