@react-aria/selection 3.21.0 → 3.22.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/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelectableCollection.main.js +68 -8
- package/dist/useSelectableCollection.main.js.map +1 -1
- package/dist/useSelectableCollection.mjs +69 -9
- package/dist/useSelectableCollection.module.js +69 -9
- package/dist/useSelectableCollection.module.js.map +1 -1
- package/dist/useSelectableItem.main.js +25 -9
- package/dist/useSelectableItem.main.js.map +1 -1
- package/dist/useSelectableItem.mjs +27 -11
- package/dist/useSelectableItem.module.js +27 -11
- package/dist/useSelectableItem.module.js.map +1 -1
- package/dist/utils.main.js +0 -5
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +2 -6
- package/dist/utils.module.js +2 -6
- package/dist/utils.module.js.map +1 -1
- package/package.json +8 -8
- package/src/useSelectableCollection.ts +80 -4
- package/src/useSelectableItem.ts +31 -14
- package/src/utils.ts +1 -9
package/dist/utils.main.js
CHANGED
|
@@ -6,7 +6,6 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
$parcel$export(module.exports, "isNonContiguousSelectionModifier", () => $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04);
|
|
9
|
-
$parcel$export(module.exports, "isCtrlKeyPressed", () => $ee0bdf4faa47f2a8$export$16792effe837dba3);
|
|
10
9
|
/*
|
|
11
10
|
* Copyright 2020 Adobe. All rights reserved.
|
|
12
11
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -23,10 +22,6 @@ function $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04(e) {
|
|
|
23
22
|
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
|
|
24
23
|
return (0, $gP8Dl$reactariautils.isAppleDevice)() ? e.altKey : e.ctrlKey;
|
|
25
24
|
}
|
|
26
|
-
function $ee0bdf4faa47f2a8$export$16792effe837dba3(e) {
|
|
27
|
-
if ((0, $gP8Dl$reactariautils.isMac)()) return e.metaKey;
|
|
28
|
-
return e.ctrlKey;
|
|
29
|
-
}
|
|
30
25
|
|
|
31
26
|
|
|
32
27
|
//# sourceMappingURL=utils.main.js.map
|
package/dist/utils.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAUM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,mCAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C","sources":["packages/@react-aria/selection/src/utils.ts"],"sourcesContent":["/*\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\nimport {isAppleDevice} from '@react-aria/utils';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event) {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {isAppleDevice as $jUnAJ$isAppleDevice
|
|
1
|
+
import {isAppleDevice as $jUnAJ$isAppleDevice} from "@react-aria/utils";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -16,11 +16,7 @@ function $feb5ffebff200149$export$d3e3bd3e26688c04(e) {
|
|
|
16
16
|
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
|
|
17
17
|
return (0, $jUnAJ$isAppleDevice)() ? e.altKey : e.ctrlKey;
|
|
18
18
|
}
|
|
19
|
-
function $feb5ffebff200149$export$16792effe837dba3(e) {
|
|
20
|
-
if ((0, $jUnAJ$isMac)()) return e.metaKey;
|
|
21
|
-
return e.ctrlKey;
|
|
22
|
-
}
|
|
23
19
|
|
|
24
20
|
|
|
25
|
-
export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier
|
|
21
|
+
export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier};
|
|
26
22
|
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {isAppleDevice as $jUnAJ$isAppleDevice
|
|
1
|
+
import {isAppleDevice as $jUnAJ$isAppleDevice} from "@react-aria/utils";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -16,11 +16,7 @@ function $feb5ffebff200149$export$d3e3bd3e26688c04(e) {
|
|
|
16
16
|
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
|
|
17
17
|
return (0, $jUnAJ$isAppleDevice)() ? e.altKey : e.ctrlKey;
|
|
18
18
|
}
|
|
19
|
-
function $feb5ffebff200149$export$16792effe837dba3(e) {
|
|
20
|
-
if ((0, $jUnAJ$isMac)()) return e.metaKey;
|
|
21
|
-
return e.ctrlKey;
|
|
22
|
-
}
|
|
23
19
|
|
|
24
20
|
|
|
25
|
-
export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier
|
|
21
|
+
export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier};
|
|
26
22
|
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,oBAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,oBAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C","sources":["packages/@react-aria/selection/src/utils.ts"],"sourcesContent":["/*\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\nimport {isAppleDevice} from '@react-aria/utils';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event) {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/selection",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.19.
|
|
26
|
-
"@react-aria/i18n": "^3.12.
|
|
27
|
-
"@react-aria/interactions": "^3.
|
|
28
|
-
"@react-aria/utils": "^3.
|
|
29
|
-
"@react-stately/selection": "^3.
|
|
30
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.19.1",
|
|
26
|
+
"@react-aria/i18n": "^3.12.5",
|
|
27
|
+
"@react-aria/interactions": "^3.23.0",
|
|
28
|
+
"@react-aria/utils": "^3.27.0",
|
|
29
|
+
"@react-stately/selection": "^3.19.0",
|
|
30
|
+
"@react-types/shared": "^3.27.0",
|
|
31
31
|
"@swc/helpers": "^0.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
|
|
41
41
|
}
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, UPDATE_ACTIVEDESCENDANT, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';
|
|
13
14
|
import {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';
|
|
14
15
|
import {flushSync} from 'react-dom';
|
|
15
16
|
import {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';
|
|
16
17
|
import {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';
|
|
17
|
-
import {focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter} from '@react-aria/utils';
|
|
18
18
|
import {getInteractionModality} from '@react-aria/interactions';
|
|
19
|
-
import {
|
|
19
|
+
import {isNonContiguousSelectionModifier} from './utils';
|
|
20
20
|
import {MultipleSelectionManager} from '@react-stately/selection';
|
|
21
21
|
import {useLocale} from '@react-aria/i18n';
|
|
22
22
|
import {useTypeSelect} from './useTypeSelect';
|
|
@@ -222,6 +222,9 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
222
222
|
}
|
|
223
223
|
case 'Home':
|
|
224
224
|
if (delegate.getFirstKey) {
|
|
225
|
+
if (manager.focusedKey === null && e.shiftKey) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
225
228
|
e.preventDefault();
|
|
226
229
|
let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));
|
|
227
230
|
manager.setFocusedKey(firstKey);
|
|
@@ -236,6 +239,9 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
236
239
|
break;
|
|
237
240
|
case 'End':
|
|
238
241
|
if (delegate.getLastKey) {
|
|
242
|
+
if (manager.focusedKey === null && e.shiftKey) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
239
245
|
e.preventDefault();
|
|
240
246
|
let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));
|
|
241
247
|
manager.setFocusedKey(lastKey);
|
|
@@ -385,6 +391,76 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
385
391
|
}
|
|
386
392
|
};
|
|
387
393
|
|
|
394
|
+
// Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types
|
|
395
|
+
// to focus the first key AFTER the collection updates.
|
|
396
|
+
// TODO: potentially expand the usage of this
|
|
397
|
+
let shouldVirtualFocusFirst = useRef(false);
|
|
398
|
+
// Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events
|
|
399
|
+
// at the autocomplete level
|
|
400
|
+
// TODO: fix type later
|
|
401
|
+
useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {
|
|
402
|
+
let {detail} = e;
|
|
403
|
+
e.stopPropagation();
|
|
404
|
+
manager.setFocused(true);
|
|
405
|
+
|
|
406
|
+
// If the user is typing forwards, autofocus the first option in the list.
|
|
407
|
+
if (detail?.focusStrategy === 'first') {
|
|
408
|
+
shouldVirtualFocusFirst.current = true;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
let updateActiveDescendant = useEffectEvent(() => {
|
|
413
|
+
let keyToFocus = delegate.getFirstKey?.() ?? null;
|
|
414
|
+
|
|
415
|
+
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist
|
|
416
|
+
if (keyToFocus == null) {
|
|
417
|
+
ref.current?.dispatchEvent(
|
|
418
|
+
new CustomEvent(UPDATE_ACTIVEDESCENDANT, {
|
|
419
|
+
cancelable: true,
|
|
420
|
+
bubbles: true
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
425
|
+
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
426
|
+
if (manager.collection.size > 0) {
|
|
427
|
+
shouldVirtualFocusFirst.current = false;
|
|
428
|
+
}
|
|
429
|
+
} else {
|
|
430
|
+
manager.setFocusedKey(keyToFocus);
|
|
431
|
+
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
432
|
+
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
433
|
+
// after the collection updates after load
|
|
434
|
+
shouldVirtualFocusFirst.current = false;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
useUpdateLayoutEffect(() => {
|
|
439
|
+
if (shouldVirtualFocusFirst.current) {
|
|
440
|
+
updateActiveDescendant();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
}, [manager.collection, updateActiveDescendant]);
|
|
444
|
+
|
|
445
|
+
let resetFocusFirstFlag = useEffectEvent(() => {
|
|
446
|
+
// If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't
|
|
447
|
+
// accidentally move focus from under them. Skip this if the collection was empty because we might be in a load
|
|
448
|
+
// state and will still want to focus the first item after load
|
|
449
|
+
if (manager.collection.size > 0) {
|
|
450
|
+
shouldVirtualFocusFirst.current = false;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
useUpdateLayoutEffect(() => {
|
|
455
|
+
resetFocusFirstFlag();
|
|
456
|
+
}, [manager.focusedKey, resetFocusFirstFlag]);
|
|
457
|
+
|
|
458
|
+
useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e) => {
|
|
459
|
+
e.stopPropagation();
|
|
460
|
+
manager.setFocused(false);
|
|
461
|
+
manager.setFocusedKey(null);
|
|
462
|
+
});
|
|
463
|
+
|
|
388
464
|
const autoFocusRef = useRef(autoFocus);
|
|
389
465
|
useEffect(() => {
|
|
390
466
|
if (autoFocusRef.current) {
|
|
@@ -480,11 +556,11 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
480
556
|
|
|
481
557
|
// If nothing is focused within the collection, make the collection itself tabbable.
|
|
482
558
|
// This will be marshalled to either the first or last item depending on where focus came from.
|
|
483
|
-
// If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
|
|
484
|
-
// to move real DOM focus to the element anyway.
|
|
485
559
|
let tabIndex: number | undefined = undefined;
|
|
486
560
|
if (!shouldUseVirtualFocus) {
|
|
487
561
|
tabIndex = manager.focusedKey == null ? 0 : -1;
|
|
562
|
+
} else {
|
|
563
|
+
tabIndex = -1;
|
|
488
564
|
}
|
|
489
565
|
|
|
490
566
|
return {
|
package/src/useSelectableItem.ts
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {DOMAttributes, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';
|
|
13
|
+
import {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';
|
|
14
14
|
import {focusSafely} from '@react-aria/focus';
|
|
15
|
-
import {isCtrlKeyPressed,
|
|
16
|
-
import {
|
|
15
|
+
import {isCtrlKeyPressed, mergeProps, openLink, UPDATE_ACTIVEDESCENDANT, useId, useRouter} from '@react-aria/utils';
|
|
16
|
+
import {isNonContiguousSelectionModifier} from './utils';
|
|
17
17
|
import {MultipleSelectionManager} from '@react-stately/selection';
|
|
18
18
|
import {PressProps, useLongPress, usePress} from '@react-aria/interactions';
|
|
19
19
|
import {useEffect, useRef} from 'react';
|
|
20
20
|
|
|
21
|
-
export interface SelectableItemOptions {
|
|
21
|
+
export interface SelectableItemOptions extends DOMProps {
|
|
22
22
|
/**
|
|
23
23
|
* An interface for reading and updating multiple selection state.
|
|
24
24
|
*/
|
|
@@ -108,6 +108,7 @@ export interface SelectableItemAria extends SelectableItemStates {
|
|
|
108
108
|
*/
|
|
109
109
|
export function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {
|
|
110
110
|
let {
|
|
111
|
+
id,
|
|
111
112
|
selectionManager: manager,
|
|
112
113
|
key,
|
|
113
114
|
ref,
|
|
@@ -120,7 +121,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
|
|
|
120
121
|
linkBehavior = 'action'
|
|
121
122
|
} = options;
|
|
122
123
|
let router = useRouter();
|
|
123
|
-
|
|
124
|
+
id = useId(id);
|
|
124
125
|
let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {
|
|
125
126
|
if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {
|
|
126
127
|
manager.toggleSelection(key);
|
|
@@ -159,13 +160,25 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
|
|
|
159
160
|
};
|
|
160
161
|
|
|
161
162
|
// Focus the associated DOM node when this item becomes the focusedKey
|
|
163
|
+
// TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs
|
|
164
|
+
// However, if this is a useEffect, it runs twice and dispatches two UPDATE_ACTIVEDESCENDANT and immediately sets
|
|
165
|
+
// aria-activeDescendant in useAutocomplete... I've worked around this for now
|
|
162
166
|
useEffect(() => {
|
|
163
167
|
let isFocused = key === manager.focusedKey;
|
|
164
|
-
if (isFocused && manager.isFocused
|
|
165
|
-
if (
|
|
166
|
-
focus
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
if (isFocused && manager.isFocused) {
|
|
169
|
+
if (!shouldUseVirtualFocus) {
|
|
170
|
+
if (focus) {
|
|
171
|
+
focus();
|
|
172
|
+
} else if (document.activeElement !== ref.current && ref.current) {
|
|
173
|
+
focusSafely(ref.current);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
let updateActiveDescendant = new CustomEvent(UPDATE_ACTIVEDESCENDANT, {
|
|
177
|
+
cancelable: true,
|
|
178
|
+
bubbles: true
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
ref.current?.dispatchEvent(updateActiveDescendant);
|
|
169
182
|
}
|
|
170
183
|
}
|
|
171
184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -241,7 +254,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
|
|
|
241
254
|
}
|
|
242
255
|
};
|
|
243
256
|
|
|
244
|
-
// If allowsDifferentPressOrigin, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)
|
|
257
|
+
// If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)
|
|
245
258
|
// Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)
|
|
246
259
|
if (!allowsDifferentPressOrigin) {
|
|
247
260
|
itemPressProps.onPress = (e) => {
|
|
@@ -257,12 +270,16 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
|
|
|
257
270
|
};
|
|
258
271
|
} else {
|
|
259
272
|
itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e) => {
|
|
260
|
-
if (e.pointerType
|
|
273
|
+
if (e.pointerType === 'mouse' && allowsSelection) {
|
|
261
274
|
onSelect(e);
|
|
262
275
|
}
|
|
263
276
|
};
|
|
264
277
|
|
|
265
|
-
itemPressProps.onPress = hasPrimaryAction ? performAction :
|
|
278
|
+
itemPressProps.onPress = hasPrimaryAction ? performAction : (e) => {
|
|
279
|
+
if (e.pointerType !== 'keyboard' && e.pointerType !== 'mouse' && allowsSelection) {
|
|
280
|
+
onSelect(e);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
266
283
|
}
|
|
267
284
|
} else {
|
|
268
285
|
itemPressProps.onPressStart = (e) => {
|
|
@@ -352,7 +369,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
|
|
|
352
369
|
itemProps,
|
|
353
370
|
allowsSelection || hasPrimaryAction ? pressProps : {},
|
|
354
371
|
longPressEnabled ? longPressProps : {},
|
|
355
|
-
{onDoubleClick, onDragStartCapture, onClick}
|
|
372
|
+
{onDoubleClick, onDragStartCapture, onClick, id}
|
|
356
373
|
),
|
|
357
374
|
isPressed,
|
|
358
375
|
isSelected: manager.isSelected(key),
|
package/src/utils.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {isAppleDevice
|
|
13
|
+
import {isAppleDevice} from '@react-aria/utils';
|
|
14
14
|
|
|
15
15
|
interface Event {
|
|
16
16
|
altKey: boolean,
|
|
@@ -23,11 +23,3 @@ export function isNonContiguousSelectionModifier(e: Event) {
|
|
|
23
23
|
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
|
|
24
24
|
return isAppleDevice() ? e.altKey : e.ctrlKey;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
export function isCtrlKeyPressed(e: Event) {
|
|
28
|
-
if (isMac()) {
|
|
29
|
-
return e.metaKey;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return e.ctrlKey;
|
|
33
|
-
}
|