|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +import {HTMLAttributes, useRef} from 'react'; |
13 | 14 | import {LongPressEvent} from '@react-types/shared';
|
14 | 15 | import {mergeProps, useDescription, useGlobalListeners} from '@react-aria/utils';
|
15 | 16 | import {usePress} from './usePress';
|
16 |
| -import {useRef} from 'react'; |
17 | 17 |
|
18 | 18 | interface LongPressProps {
|
19 | 19 | /** Whether long press events should be disabled. */
|
@@ -42,9 +42,18 @@ interface LongPressProps {
|
42 | 42 | accessibilityDescription?: string
|
43 | 43 | }
|
44 | 44 |
|
| 45 | +interface LongPressResult { |
| 46 | + /** Props to spread on the target element. */ |
| 47 | + longPressProps: HTMLAttributes<HTMLElement> |
| 48 | +} |
| 49 | + |
45 | 50 | const DEFAULT_THRESHOLD = 500;
|
46 | 51 |
|
47 |
| -export function useLongPress(props: LongPressProps) { |
| 52 | +/** |
| 53 | + * Handles long press interactions across mouse and touch devices. Supports a customizable time threshold, |
| 54 | + * accessibility description, and normalizes behavior across browsers and devices. |
| 55 | + */ |
| 56 | +export function useLongPress(props: LongPressProps): LongPressResult { |
48 | 57 | let {
|
49 | 58 | isDisabled,
|
50 | 59 | onLongPressStart,
|
@@ -102,7 +111,7 @@ export function useLongPress(props: LongPressProps) {
|
102 | 111 | clearTimeout(timeRef.current);
|
103 | 112 | }
|
104 | 113 |
|
105 |
| - if (onLongPressEnd) { |
| 114 | + if (onLongPressEnd && (e.pointerType === 'mouse' || e.pointerType === 'touch')) { |
106 | 115 | onLongPressEnd({
|
107 | 116 | ...e,
|
108 | 117 | type: 'longpressend'
|
|
0 commit comments