@react-aria/interactions 3.18.0 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +77 -43
- package/dist/main.js +76 -41
- package/dist/main.js.map +1 -1
- package/dist/module.js +77 -43
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/PressResponder.tsx +8 -0
- package/src/index.ts +1 -1
- package/src/usePress.ts +58 -22
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AEuBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,OAAO,CAAC,CAAA;CACzB;
|
|
1
|
+
{"mappings":";;AEuBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,OAAO,CAAC,CAAA;CACzB;AAwBD;IACE,+CAA+C;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,cAAc;IACnD,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,+CAA+C;IAC/C,aAAa,EAAE,aAAa,CAAA;CAC7B;AAED;;GAEG;AACH,4BAA4B,KAAK,EAAE,aAAa,GAAG,cAAc,CAOhE;AClBD;IACE,6CAA6C;IAC7C,SAAS,EAAE,aAAa,CAAA;CACzB;AASD;;;;GAIG;AACH,wBAAwB,KAAK,EAAE,UAAU,GAAG,UAAU,CAoMrD;ACtND,iCAAkC,SAAQ,YAAY;IACpD,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAGD,+BAA+B,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,IAAI,CAkBzF;ACvBD;IACE,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC;AAED;IACE,6CAA6C;IAC7C,cAAc,EAAE,aAAa,CAAA;CAC9B;AAID;;;GAGG;AACH,6BAA6B,KAAK,EAAE,cAAc,GAAG,eAAe,CAyEnE;ACzFD,YAAY,EAAC,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {Pressable} from './Pressable';\nexport {PressResponder, ClearPressResponder} from './PressResponder';\nexport {useFocus} from './useFocus';\nexport {\n isFocusVisible,\n getInteractionModality,\n setInteractionModality,\n useInteractionModality,\n useFocusVisible,\n useFocusVisibleListener\n} from './useFocusVisible';\nexport {useFocusWithin} from './useFocusWithin';\nexport {useHover} from './useHover';\nexport {useInteractOutside} from './useInteractOutside';\nexport {useKeyboard} from './useKeyboard';\nexport {useMove} from './useMove';\nexport {usePress} from './usePress';\nexport {useScrollWheel} from './useScrollWheel';\nexport {useLongPress} from './useLongPress';\n\nexport type {FocusProps, FocusResult} from './useFocus';\nexport type {FocusVisibleHandler, FocusVisibleProps, FocusVisibleResult, Modality} from './useFocusVisible';\nexport type {FocusWithinProps, FocusWithinResult} from './useFocusWithin';\nexport type {HoverProps, HoverResult} from './useHover';\nexport type {InteractOutsideProps} from './useInteractOutside';\nexport type {KeyboardProps, KeyboardResult} from './useKeyboard';\nexport type {PressProps, PressHookProps, PressResult} from './usePress';\nexport type {PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents} from '@react-types/shared';\nexport type {MoveResult} from './useMove';\nexport type {LongPressProps, LongPressResult} from './useLongPress';\nexport type {ScrollWheelProps} from './useScrollWheel';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/interactions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@react-aria/ssr": "^3.8.0",
|
|
26
|
-
"@react-aria/utils": "^3.
|
|
27
|
-
"@react-types/shared": "^3.
|
|
26
|
+
"@react-aria/utils": "^3.21.0",
|
|
27
|
+
"@react-types/shared": "^3.21.0",
|
|
28
28
|
"@swc/helpers": "^0.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
|
|
37
37
|
}
|
package/src/PressResponder.tsx
CHANGED
|
@@ -52,3 +52,11 @@ export const PressResponder = React.forwardRef(({children, ...props}: PressRespo
|
|
|
52
52
|
</PressResponderContext.Provider>
|
|
53
53
|
);
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
export function ClearPressResponder({children}: {children: ReactNode}) {
|
|
57
|
+
return (
|
|
58
|
+
<PressResponderContext.Provider value={undefined}>
|
|
59
|
+
{children}
|
|
60
|
+
</PressResponderContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
}
|
package/src/index.ts
CHANGED
package/src/usePress.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import {disableTextSelection, restoreTextSelection} from './textSelection';
|
|
19
19
|
import {DOMAttributes, FocusableElement, PressEvent as IPressEvent, PointerType, PressEvents} from '@react-types/shared';
|
|
20
|
-
import {focusWithoutScrolling, isVirtualClick, isVirtualPointerEvent, mergeProps, useEffectEvent, useGlobalListeners, useSyncRef} from '@react-aria/utils';
|
|
20
|
+
import {focusWithoutScrolling, isMac, isVirtualClick, isVirtualPointerEvent, mergeProps, openLink, useEffectEvent, useGlobalListeners, useSyncRef} from '@react-aria/utils';
|
|
21
21
|
import {PressResponderContext} from './context';
|
|
22
22
|
import {RefObject, useContext, useEffect, useMemo, useRef, useState} from 'react';
|
|
23
23
|
|
|
@@ -49,11 +49,13 @@ interface PressState {
|
|
|
49
49
|
ignoreEmulatedMouseEvents: boolean,
|
|
50
50
|
ignoreClickAfterPress: boolean,
|
|
51
51
|
didFirePressStart: boolean,
|
|
52
|
+
isTriggeringEvent: boolean,
|
|
52
53
|
activePointerId: any,
|
|
53
54
|
target: FocusableElement | null,
|
|
54
55
|
isOverTarget: boolean,
|
|
55
56
|
pointerType: PointerType,
|
|
56
|
-
userSelect?: string
|
|
57
|
+
userSelect?: string,
|
|
58
|
+
metaKeyEvents?: Map<string, KeyboardEvent>
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
interface EventBase {
|
|
@@ -113,6 +115,8 @@ class PressEvent implements IPressEvent {
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
const LINK_CLICKED = Symbol('linkClicked');
|
|
119
|
+
|
|
116
120
|
/**
|
|
117
121
|
* Handles press interactions across mouse, touch, keyboard, and screen readers.
|
|
118
122
|
* It normalizes behavior across browsers and platforms, and handles many nuances
|
|
@@ -141,6 +145,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
141
145
|
ignoreEmulatedMouseEvents: false,
|
|
142
146
|
ignoreClickAfterPress: false,
|
|
143
147
|
didFirePressStart: false,
|
|
148
|
+
isTriggeringEvent: false,
|
|
144
149
|
activePointerId: null,
|
|
145
150
|
target: null,
|
|
146
151
|
isOverTarget: false,
|
|
@@ -156,6 +161,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
let shouldStopPropagation = true;
|
|
164
|
+
state.isTriggeringEvent = true;
|
|
159
165
|
if (onPressStart) {
|
|
160
166
|
let event = new PressEvent('pressstart', pointerType, originalEvent);
|
|
161
167
|
onPressStart(event);
|
|
@@ -166,6 +172,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
166
172
|
onPressChange(true);
|
|
167
173
|
}
|
|
168
174
|
|
|
175
|
+
state.isTriggeringEvent = false;
|
|
169
176
|
state.didFirePressStart = true;
|
|
170
177
|
setPressed(true);
|
|
171
178
|
return shouldStopPropagation;
|
|
@@ -179,6 +186,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
179
186
|
|
|
180
187
|
state.ignoreClickAfterPress = true;
|
|
181
188
|
state.didFirePressStart = false;
|
|
189
|
+
state.isTriggeringEvent = true;
|
|
182
190
|
|
|
183
191
|
let shouldStopPropagation = true;
|
|
184
192
|
if (onPressEnd) {
|
|
@@ -199,17 +207,21 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
199
207
|
shouldStopPropagation &&= event.shouldStopPropagation;
|
|
200
208
|
}
|
|
201
209
|
|
|
210
|
+
state.isTriggeringEvent = false;
|
|
202
211
|
return shouldStopPropagation;
|
|
203
212
|
});
|
|
204
213
|
|
|
205
214
|
let triggerPressUp = useEffectEvent((originalEvent: EventBase, pointerType: PointerType) => {
|
|
215
|
+
let state = ref.current;
|
|
206
216
|
if (isDisabled) {
|
|
207
217
|
return;
|
|
208
218
|
}
|
|
209
219
|
|
|
210
220
|
if (onPressUp) {
|
|
221
|
+
state.isTriggeringEvent = true;
|
|
211
222
|
let event = new PressEvent('pressup', pointerType, originalEvent);
|
|
212
223
|
onPressUp(event);
|
|
224
|
+
state.isTriggeringEvent = false;
|
|
213
225
|
return event.shouldStopPropagation;
|
|
214
226
|
}
|
|
215
227
|
|
|
@@ -265,11 +277,19 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
265
277
|
if (shouldStopPropagation) {
|
|
266
278
|
e.stopPropagation();
|
|
267
279
|
}
|
|
268
|
-
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
|
|
280
|
+
|
|
281
|
+
// Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.
|
|
282
|
+
// macOS has a bug where keyup events are not fired while the Meta key is down.
|
|
283
|
+
// When the Meta key itself is released we will get an event for that, and we'll act as if
|
|
284
|
+
// all of these other keys were released as well.
|
|
285
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1393524
|
|
286
|
+
// https://bugs.webkit.org/show_bug.cgi?id=55291
|
|
287
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1299553
|
|
288
|
+
if (e.metaKey && isMac()) {
|
|
289
|
+
state.metaKeyEvents.set(e.key, e.nativeEvent);
|
|
290
|
+
}
|
|
291
|
+
} else if (e.key === 'Meta') {
|
|
292
|
+
state.metaKeyEvents = new Map();
|
|
273
293
|
}
|
|
274
294
|
},
|
|
275
295
|
onKeyUp(e) {
|
|
@@ -282,7 +302,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
282
302
|
return;
|
|
283
303
|
}
|
|
284
304
|
|
|
285
|
-
if (e && e.button === 0) {
|
|
305
|
+
if (e && e.button === 0 && !state.isTriggeringEvent && !openLink.isOpening) {
|
|
286
306
|
let shouldStopPropagation = true;
|
|
287
307
|
if (isDisabled) {
|
|
288
308
|
e.preventDefault();
|
|
@@ -290,7 +310,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
290
310
|
|
|
291
311
|
// If triggered from a screen reader or by using element.click(),
|
|
292
312
|
// trigger as if it were a keyboard click.
|
|
293
|
-
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || isVirtualClick(e.nativeEvent))) {
|
|
313
|
+
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && !state.isPressed && (state.pointerType === 'virtual' || isVirtualClick(e.nativeEvent))) {
|
|
294
314
|
// Ensure the element receives focus (VoiceOver on iOS does not do this)
|
|
295
315
|
if (!isDisabled && !preventFocusOnPress) {
|
|
296
316
|
focusWithoutScrolling(e.currentTarget);
|
|
@@ -317,7 +337,6 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
317
337
|
e.preventDefault();
|
|
318
338
|
}
|
|
319
339
|
|
|
320
|
-
state.isPressed = false;
|
|
321
340
|
let target = e.target as Element;
|
|
322
341
|
let shouldStopPropagation = triggerPressEnd(createEvent(state.target, e), 'keyboard', state.target.contains(target));
|
|
323
342
|
removeAllGlobalListeners();
|
|
@@ -326,10 +345,26 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
326
345
|
e.stopPropagation();
|
|
327
346
|
}
|
|
328
347
|
|
|
329
|
-
// If
|
|
330
|
-
//
|
|
331
|
-
|
|
332
|
-
|
|
348
|
+
// If a link was triggered with a key other than Enter, open the URL ourselves.
|
|
349
|
+
// This means the link has a role override, and the default browser behavior
|
|
350
|
+
// only applies when using the Enter key.
|
|
351
|
+
if (e.key !== 'Enter' && isHTMLAnchorLink(state.target) && state.target.contains(target) && !e[LINK_CLICKED]) {
|
|
352
|
+
// Store a hidden property on the event so we only trigger link click once,
|
|
353
|
+
// even if there are multiple usePress instances attached to the element.
|
|
354
|
+
e[LINK_CLICKED] = true;
|
|
355
|
+
openLink(state.target, e, false);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
state.isPressed = false;
|
|
359
|
+
state.metaKeyEvents?.delete(e.key);
|
|
360
|
+
} else if (e.key === 'Meta' && state.metaKeyEvents?.size) {
|
|
361
|
+
// If we recorded keydown events that occurred while the Meta key was pressed,
|
|
362
|
+
// and those haven't received keyup events already, fire keyup events ourselves.
|
|
363
|
+
// See comment above for more info about the macOS bug causing this.
|
|
364
|
+
let events = state.metaKeyEvents;
|
|
365
|
+
state.metaKeyEvents = null;
|
|
366
|
+
for (let event of events.values()) {
|
|
367
|
+
state.target.dispatchEvent(new KeyboardEvent('keyup', event));
|
|
333
368
|
}
|
|
334
369
|
}
|
|
335
370
|
};
|
|
@@ -541,7 +576,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
541
576
|
}
|
|
542
577
|
|
|
543
578
|
if (!state.ignoreEmulatedMouseEvents && e.button === 0) {
|
|
544
|
-
triggerPressUp(e, state.pointerType);
|
|
579
|
+
triggerPressUp(e, state.pointerType || 'mouse');
|
|
545
580
|
}
|
|
546
581
|
};
|
|
547
582
|
|
|
@@ -726,7 +761,7 @@ export function usePress(props: PressHookProps): PressResult {
|
|
|
726
761
|
};
|
|
727
762
|
}
|
|
728
763
|
|
|
729
|
-
function isHTMLAnchorLink(target: Element):
|
|
764
|
+
function isHTMLAnchorLink(target: Element): target is HTMLAnchorElement {
|
|
730
765
|
return target.tagName === 'A' && target.hasAttribute('href');
|
|
731
766
|
}
|
|
732
767
|
|
|
@@ -741,11 +776,8 @@ function isValidKeyboardEvent(event: KeyboardEvent, currentTarget: Element): boo
|
|
|
741
776
|
!((element instanceof HTMLInputElement && !isValidInputKey(element, key)) ||
|
|
742
777
|
element instanceof HTMLTextAreaElement ||
|
|
743
778
|
element.isContentEditable) &&
|
|
744
|
-
//
|
|
745
|
-
|
|
746
|
-
(!isHTMLAnchorLink(element) || (role === 'button' && key !== 'Enter')) &&
|
|
747
|
-
// An element with role='link' should only trigger with Enter key
|
|
748
|
-
!(role === 'link' && key !== 'Enter')
|
|
779
|
+
// Links should only trigger with Enter key
|
|
780
|
+
!((role === 'link' || (!role && isHTMLAnchorLink(element))) && key !== 'Enter')
|
|
749
781
|
);
|
|
750
782
|
}
|
|
751
783
|
|
|
@@ -829,7 +861,7 @@ function isOverTarget(point: EventPoint, target: Element) {
|
|
|
829
861
|
|
|
830
862
|
function shouldPreventDefault(target: Element) {
|
|
831
863
|
// We cannot prevent default if the target is a draggable element.
|
|
832
|
-
return !(target instanceof HTMLElement) || !target.draggable;
|
|
864
|
+
return !(target instanceof HTMLElement) || !target.hasAttribute('draggable');
|
|
833
865
|
}
|
|
834
866
|
|
|
835
867
|
function shouldPreventDefaultKeyboard(target: Element, key: string) {
|
|
@@ -841,6 +873,10 @@ function shouldPreventDefaultKeyboard(target: Element, key: string) {
|
|
|
841
873
|
return target.type !== 'submit' && target.type !== 'reset';
|
|
842
874
|
}
|
|
843
875
|
|
|
876
|
+
if (isHTMLAnchorLink(target)) {
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
|
|
844
880
|
return true;
|
|
845
881
|
}
|
|
846
882
|
|