@react-aria/selection 3.0.0-alpha.1 → 3.0.0-nightly-641446f65-240905
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/README.md +1 -1
- package/dist/DOMLayoutDelegate.main.js +53 -0
- package/dist/DOMLayoutDelegate.main.js.map +1 -0
- package/dist/DOMLayoutDelegate.mjs +48 -0
- package/dist/DOMLayoutDelegate.module.js +48 -0
- package/dist/DOMLayoutDelegate.module.js.map +1 -0
- package/dist/ListKeyboardDelegate.main.js +189 -0
- package/dist/ListKeyboardDelegate.main.js.map +1 -0
- package/dist/ListKeyboardDelegate.mjs +184 -0
- package/dist/ListKeyboardDelegate.module.js +184 -0
- package/dist/ListKeyboardDelegate.module.js.map +1 -0
- package/dist/import.mjs +27 -0
- package/dist/main.js +16 -608
- package/dist/main.js.map +1 -0
- package/dist/module.js +9 -563
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +218 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelectableCollection.main.js +318 -0
- package/dist/useSelectableCollection.main.js.map +1 -0
- package/dist/useSelectableCollection.mjs +313 -0
- package/dist/useSelectableCollection.module.js +313 -0
- package/dist/useSelectableCollection.module.js.map +1 -0
- package/dist/useSelectableItem.main.js +213 -0
- package/dist/useSelectableItem.main.js.map +1 -0
- package/dist/useSelectableItem.mjs +208 -0
- package/dist/useSelectableItem.module.js +208 -0
- package/dist/useSelectableItem.module.js.map +1 -0
- package/dist/useSelectableList.main.js +63 -0
- package/dist/useSelectableList.main.js.map +1 -0
- package/dist/useSelectableList.mjs +58 -0
- package/dist/useSelectableList.module.js +58 -0
- package/dist/useSelectableList.module.js.map +1 -0
- package/dist/useTypeSelect.main.js +73 -0
- package/dist/useTypeSelect.main.js.map +1 -0
- package/dist/useTypeSelect.mjs +68 -0
- package/dist/useTypeSelect.module.js +68 -0
- package/dist/useTypeSelect.module.js.map +1 -0
- package/dist/utils.main.js +32 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +26 -0
- package/dist/utils.module.js +26 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +20 -13
- package/src/DOMLayoutDelegate.ts +57 -0
- package/src/ListKeyboardDelegate.ts +288 -0
- package/src/index.ts +23 -0
- package/src/useSelectableCollection.ts +490 -0
- package/src/useSelectableItem.ts +374 -0
- package/src/useSelectableList.ts +85 -0
- package/src/useTypeSelect.ts +114 -0
- package/src/utils.ts +33 -0
- package/LICENSE +0 -201
package/dist/types.d.ts
CHANGED
|
@@ -1,65 +1,253 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { KeyboardDelegate } from "@react-types/shared";
|
|
1
|
+
import { DOMAttributes, Key, KeyboardDelegate, FocusStrategy, RefObject, FocusableElement, LayoutDelegate, Rect, Size, Collection, Direction, DisabledBehavior, Node, Orientation } from "@react-types/shared";
|
|
3
2
|
import { MultipleSelectionManager } from "@react-stately/selection";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export interface AriaTypeSelectOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A delegate that returns collection item keys with respect to visual layout.
|
|
6
|
+
*/
|
|
8
7
|
keyboardDelegate: KeyboardDelegate;
|
|
8
|
+
/**
|
|
9
|
+
* An interface for reading and updating multiple selection state.
|
|
10
|
+
*/
|
|
9
11
|
selectionManager: MultipleSelectionManager;
|
|
12
|
+
/**
|
|
13
|
+
* Called when an item is focused by typing.
|
|
14
|
+
*/
|
|
10
15
|
onTypeSelect?: (key: Key) => void;
|
|
11
16
|
}
|
|
12
|
-
interface TypeSelectAria {
|
|
13
|
-
|
|
17
|
+
export interface TypeSelectAria {
|
|
18
|
+
/**
|
|
19
|
+
* Props to be spread on the owner of the options.
|
|
20
|
+
*/
|
|
21
|
+
typeSelectProps: DOMAttributes;
|
|
14
22
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Handles typeahead interactions with collections.
|
|
25
|
+
*/
|
|
26
|
+
export function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria;
|
|
27
|
+
export interface AriaSelectableCollectionOptions {
|
|
28
|
+
/**
|
|
29
|
+
* An interface for reading and updating multiple selection state.
|
|
30
|
+
*/
|
|
18
31
|
selectionManager: MultipleSelectionManager;
|
|
32
|
+
/**
|
|
33
|
+
* A delegate object that implements behavior for keyboard focus movement.
|
|
34
|
+
*/
|
|
19
35
|
keyboardDelegate: KeyboardDelegate;
|
|
36
|
+
/**
|
|
37
|
+
* The ref attached to the element representing the collection.
|
|
38
|
+
*/
|
|
39
|
+
ref: RefObject<HTMLElement | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the collection or one of its items should be automatically focused upon render.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
20
44
|
autoFocus?: boolean | FocusStrategy;
|
|
45
|
+
/**
|
|
46
|
+
* Whether focus should wrap around when the end/start is reached.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
21
49
|
shouldFocusWrap?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the collection allows empty selection.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
22
54
|
disallowEmptySelection?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the collection allows the user to select all items via keyboard shortcut.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
23
59
|
disallowSelectAll?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether selection should occur automatically on focus.
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
selectOnFocus?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether typeahead is disabled.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
disallowTypeAhead?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the collection items should use virtual focus instead of being focused directly.
|
|
72
|
+
*/
|
|
73
|
+
shouldUseVirtualFocus?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether navigation through tab key is enabled.
|
|
76
|
+
*/
|
|
77
|
+
allowsTabNavigation?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the collection items are contained in a virtual scroller.
|
|
80
|
+
*/
|
|
81
|
+
isVirtualized?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.
|
|
84
|
+
* If not provided, defaults to the collection ref.
|
|
85
|
+
*/
|
|
86
|
+
scrollRef?: RefObject<HTMLElement | null>;
|
|
87
|
+
/**
|
|
88
|
+
* The behavior of links in the collection.
|
|
89
|
+
* - 'action': link behaves like onAction.
|
|
90
|
+
* - 'selection': link follows selection interactions (e.g. if URL drives selection).
|
|
91
|
+
* - 'override': links override all other interactions (link items are not selectable).
|
|
92
|
+
* @default 'action'
|
|
93
|
+
*/
|
|
94
|
+
linkBehavior?: 'action' | 'selection' | 'override';
|
|
24
95
|
}
|
|
25
|
-
interface SelectableCollectionAria {
|
|
26
|
-
|
|
96
|
+
export interface SelectableCollectionAria {
|
|
97
|
+
/** Props for the collection element. */
|
|
98
|
+
collectionProps: DOMAttributes;
|
|
27
99
|
}
|
|
28
|
-
|
|
29
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Handles interactions with selectable collections.
|
|
102
|
+
*/
|
|
103
|
+
export function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria;
|
|
104
|
+
export interface SelectableItemOptions {
|
|
105
|
+
/**
|
|
106
|
+
* An interface for reading and updating multiple selection state.
|
|
107
|
+
*/
|
|
30
108
|
selectionManager: MultipleSelectionManager;
|
|
31
|
-
|
|
32
|
-
|
|
109
|
+
/**
|
|
110
|
+
* A unique key for the item.
|
|
111
|
+
*/
|
|
112
|
+
key: Key;
|
|
113
|
+
/**
|
|
114
|
+
* Ref to the item.
|
|
115
|
+
*/
|
|
116
|
+
ref: RefObject<FocusableElement | null>;
|
|
117
|
+
/**
|
|
118
|
+
* By default, selection occurs on pointer down. This can be strange if selecting an
|
|
119
|
+
* item causes the UI to disappear immediately (e.g. menus).
|
|
120
|
+
*/
|
|
33
121
|
shouldSelectOnPressUp?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on
|
|
124
|
+
* the target of the pointer/mouse up event.
|
|
125
|
+
*/
|
|
126
|
+
allowsDifferentPressOrigin?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Whether the option is contained in a virtual scroller.
|
|
129
|
+
*/
|
|
34
130
|
isVirtualized?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Function to focus the item.
|
|
133
|
+
*/
|
|
134
|
+
focus?: () => void;
|
|
135
|
+
/**
|
|
136
|
+
* Whether the option should use virtual focus instead of being focused directly.
|
|
137
|
+
*/
|
|
138
|
+
shouldUseVirtualFocus?: boolean;
|
|
139
|
+
/** Whether the item is disabled. */
|
|
140
|
+
isDisabled?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Handler that is called when a user performs an action on the item. The exact user event depends on
|
|
143
|
+
* the collection's `selectionBehavior` prop and the interaction modality.
|
|
144
|
+
*/
|
|
145
|
+
onAction?: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* The behavior of links in the collection.
|
|
148
|
+
* - 'action': link behaves like onAction.
|
|
149
|
+
* - 'selection': link follows selection interactions (e.g. if URL drives selection).
|
|
150
|
+
* - 'override': links override all other interactions (link items are not selectable).
|
|
151
|
+
* - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).
|
|
152
|
+
* @default 'action'
|
|
153
|
+
*/
|
|
154
|
+
linkBehavior?: 'action' | 'selection' | 'override' | 'none';
|
|
155
|
+
}
|
|
156
|
+
export interface SelectableItemStates {
|
|
157
|
+
/** Whether the item is currently in a pressed state. */
|
|
158
|
+
isPressed: boolean;
|
|
159
|
+
/** Whether the item is currently selected. */
|
|
160
|
+
isSelected: boolean;
|
|
161
|
+
/** Whether the item is currently focused. */
|
|
162
|
+
isFocused: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may
|
|
165
|
+
* not be focused. Dependent on `disabledKeys` and `disabledBehavior`.
|
|
166
|
+
*/
|
|
167
|
+
isDisabled: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.
|
|
170
|
+
*/
|
|
171
|
+
allowsSelection: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Whether the item has an action, dependent on `onAction`, `disabledKeys`,
|
|
174
|
+
* and `disabledBehavior`. It may also change depending on the current selection state
|
|
175
|
+
* of the list (e.g. when selection is primary). This can be used to enable or disable hover
|
|
176
|
+
* styles or other visual indications of interactivity.
|
|
177
|
+
*/
|
|
178
|
+
hasAction: boolean;
|
|
35
179
|
}
|
|
36
|
-
interface SelectableItemAria {
|
|
37
|
-
|
|
180
|
+
export interface SelectableItemAria extends SelectableItemStates {
|
|
181
|
+
/**
|
|
182
|
+
* Props to be spread on the item root node.
|
|
183
|
+
*/
|
|
184
|
+
itemProps: DOMAttributes;
|
|
38
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Handles interactions with an item in a selectable collection.
|
|
188
|
+
*/
|
|
39
189
|
export function useSelectableItem(options: SelectableItemOptions): SelectableItemAria;
|
|
190
|
+
export class DOMLayoutDelegate implements LayoutDelegate {
|
|
191
|
+
constructor(ref: RefObject<HTMLElement>);
|
|
192
|
+
getItemRect(key: Key): Rect | null;
|
|
193
|
+
getContentSize(): Size;
|
|
194
|
+
getVisibleRect(): Rect;
|
|
195
|
+
}
|
|
196
|
+
interface ListKeyboardDelegateOptions<T> {
|
|
197
|
+
collection: Collection<Node<T>>;
|
|
198
|
+
ref: RefObject<HTMLElement | null>;
|
|
199
|
+
collator?: Intl.Collator;
|
|
200
|
+
layout?: 'stack' | 'grid';
|
|
201
|
+
orientation?: Orientation;
|
|
202
|
+
direction?: Direction;
|
|
203
|
+
disabledKeys?: Set<Key>;
|
|
204
|
+
disabledBehavior?: DisabledBehavior;
|
|
205
|
+
layoutDelegate?: LayoutDelegate;
|
|
206
|
+
}
|
|
40
207
|
export class ListKeyboardDelegate<T> implements KeyboardDelegate {
|
|
41
|
-
constructor(collection: Collection<Node<T>>, ref: RefObject<HTMLElement>, collator?: Intl.Collator);
|
|
208
|
+
constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);
|
|
209
|
+
constructor(options: ListKeyboardDelegateOptions<T>);
|
|
210
|
+
getNextKey(key: Key): Key;
|
|
211
|
+
getPreviousKey(key: Key): Key;
|
|
42
212
|
getKeyBelow(key: Key): Key;
|
|
43
213
|
getKeyAbove(key: Key): Key;
|
|
214
|
+
getKeyRightOf(key: Key): Key;
|
|
215
|
+
getKeyLeftOf(key: Key): Key;
|
|
44
216
|
getFirstKey(): Key;
|
|
45
217
|
getLastKey(): Key;
|
|
46
218
|
getKeyPageAbove(key: Key): Key;
|
|
47
219
|
getKeyPageBelow(key: Key): Key;
|
|
48
220
|
getKeyForSearch(search: string, fromKey?: Key): Key;
|
|
49
221
|
}
|
|
50
|
-
interface
|
|
51
|
-
|
|
222
|
+
export interface AriaSelectableListOptions extends Omit<AriaSelectableCollectionOptions, 'keyboardDelegate'> {
|
|
223
|
+
/**
|
|
224
|
+
* State of the collection.
|
|
225
|
+
*/
|
|
52
226
|
collection: Collection<Node<unknown>>;
|
|
53
|
-
|
|
227
|
+
/**
|
|
228
|
+
* A delegate object that implements behavior for keyboard focus movement.
|
|
229
|
+
*/
|
|
54
230
|
keyboardDelegate?: KeyboardDelegate;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
231
|
+
/**
|
|
232
|
+
* A delegate object that provides layout information for items in the collection.
|
|
233
|
+
* By default this uses the DOM, but this can be overridden to implement things like
|
|
234
|
+
* virtualized scrolling.
|
|
235
|
+
*/
|
|
236
|
+
layoutDelegate?: LayoutDelegate;
|
|
237
|
+
/**
|
|
238
|
+
* The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
|
|
239
|
+
*/
|
|
240
|
+
disabledKeys: Set<Key>;
|
|
59
241
|
}
|
|
60
|
-
interface SelectableListAria {
|
|
61
|
-
|
|
242
|
+
export interface SelectableListAria {
|
|
243
|
+
/**
|
|
244
|
+
* Props for the option element.
|
|
245
|
+
*/
|
|
246
|
+
listProps: DOMAttributes;
|
|
62
247
|
}
|
|
63
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Handles interactions with a selectable list.
|
|
250
|
+
*/
|
|
251
|
+
export function useSelectableList(props: AriaSelectableListOptions): SelectableListAria;
|
|
64
252
|
|
|
65
253
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/DOMLayoutDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[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 {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
var $ee0bdf4faa47f2a8$exports = require("./utils.main.js");
|
|
2
|
+
var $a1189052f36475e8$exports = require("./useTypeSelect.main.js");
|
|
3
|
+
var $bT8Bh$reactdom = require("react-dom");
|
|
4
|
+
var $bT8Bh$react = require("react");
|
|
5
|
+
var $bT8Bh$reactariafocus = require("@react-aria/focus");
|
|
6
|
+
var $bT8Bh$reactariautils = require("@react-aria/utils");
|
|
7
|
+
var $bT8Bh$reactariainteractions = require("@react-aria/interactions");
|
|
8
|
+
var $bT8Bh$reactariai18n = require("@react-aria/i18n");
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function $parcel$export(e, n, v, s) {
|
|
12
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$parcel$export(module.exports, "useSelectableCollection", () => $b6837c2f80a3c32f$export$d6daf82dcd84e87c);
|
|
16
|
+
/*
|
|
17
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
18
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
20
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
23
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
24
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
25
|
+
* governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
|
|
35
|
+
let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
|
|
36
|
+
scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
|
|
37
|
+
let { direction: direction } = (0, $bT8Bh$reactariai18n.useLocale)();
|
|
38
|
+
let router = (0, $bT8Bh$reactariautils.useRouter)();
|
|
39
|
+
let onKeyDown = (e)=>{
|
|
40
|
+
// Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
|
|
41
|
+
if (e.altKey && e.key === 'Tab') e.preventDefault();
|
|
42
|
+
// Keyboard events bubble through portals. Don't handle keyboard events
|
|
43
|
+
// for elements outside the collection (e.g. menus).
|
|
44
|
+
if (!ref.current.contains(e.target)) return;
|
|
45
|
+
const navigateToKey = (key, childFocus)=>{
|
|
46
|
+
if (key != null) {
|
|
47
|
+
if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !(0, $ee0bdf4faa47f2a8$exports.isNonContiguousSelectionModifier)(e)) {
|
|
48
|
+
// Set focused key and re-render synchronously to bring item into view if needed.
|
|
49
|
+
(0, $bT8Bh$reactdom.flushSync)(()=>{
|
|
50
|
+
manager.setFocusedKey(key, childFocus);
|
|
51
|
+
});
|
|
52
|
+
let item = scrollRef.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
|
|
53
|
+
let itemProps = manager.getItemProps(key);
|
|
54
|
+
router.open(item, e, itemProps.href, itemProps.routerOptions);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
manager.setFocusedKey(key, childFocus);
|
|
58
|
+
if (manager.isLink(key) && linkBehavior === 'override') return;
|
|
59
|
+
if (e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(key);
|
|
60
|
+
else if (selectOnFocus && !(0, $ee0bdf4faa47f2a8$exports.isNonContiguousSelectionModifier)(e)) manager.replaceSelection(key);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
switch(e.key){
|
|
64
|
+
case 'ArrowDown':
|
|
65
|
+
if (delegate.getKeyBelow) {
|
|
66
|
+
var _delegate_getKeyBelow, _delegate_getFirstKey, _delegate_getFirstKey1;
|
|
67
|
+
let nextKey = manager.focusedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, manager.focusedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
|
|
68
|
+
if (nextKey == null && shouldFocusWrap) nextKey = (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate, manager.focusedKey);
|
|
69
|
+
if (nextKey != null) {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
navigateToKey(nextKey);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case 'ArrowUp':
|
|
76
|
+
if (delegate.getKeyAbove) {
|
|
77
|
+
var _delegate_getKeyAbove, _delegate_getLastKey, _delegate_getLastKey1;
|
|
78
|
+
let nextKey = manager.focusedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, manager.focusedKey) : (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate);
|
|
79
|
+
if (nextKey == null && shouldFocusWrap) nextKey = (_delegate_getLastKey1 = delegate.getLastKey) === null || _delegate_getLastKey1 === void 0 ? void 0 : _delegate_getLastKey1.call(delegate, manager.focusedKey);
|
|
80
|
+
if (nextKey != null) {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
navigateToKey(nextKey);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'ArrowLeft':
|
|
87
|
+
if (delegate.getKeyLeftOf) {
|
|
88
|
+
var _delegate_getKeyLeftOf, _delegate_getFirstKey2, _delegate_getLastKey2;
|
|
89
|
+
let nextKey = (_delegate_getKeyLeftOf = delegate.getKeyLeftOf) === null || _delegate_getKeyLeftOf === void 0 ? void 0 : _delegate_getKeyLeftOf.call(delegate, manager.focusedKey);
|
|
90
|
+
if (nextKey == null && shouldFocusWrap) nextKey = direction === 'rtl' ? (_delegate_getFirstKey2 = delegate.getFirstKey) === null || _delegate_getFirstKey2 === void 0 ? void 0 : _delegate_getFirstKey2.call(delegate, manager.focusedKey) : (_delegate_getLastKey2 = delegate.getLastKey) === null || _delegate_getLastKey2 === void 0 ? void 0 : _delegate_getLastKey2.call(delegate, manager.focusedKey);
|
|
91
|
+
if (nextKey != null) {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case 'ArrowRight':
|
|
98
|
+
if (delegate.getKeyRightOf) {
|
|
99
|
+
var _delegate_getKeyRightOf, _delegate_getLastKey3, _delegate_getFirstKey3;
|
|
100
|
+
let nextKey = (_delegate_getKeyRightOf = delegate.getKeyRightOf) === null || _delegate_getKeyRightOf === void 0 ? void 0 : _delegate_getKeyRightOf.call(delegate, manager.focusedKey);
|
|
101
|
+
if (nextKey == null && shouldFocusWrap) nextKey = direction === 'rtl' ? (_delegate_getLastKey3 = delegate.getLastKey) === null || _delegate_getLastKey3 === void 0 ? void 0 : _delegate_getLastKey3.call(delegate, manager.focusedKey) : (_delegate_getFirstKey3 = delegate.getFirstKey) === null || _delegate_getFirstKey3 === void 0 ? void 0 : _delegate_getFirstKey3.call(delegate, manager.focusedKey);
|
|
102
|
+
if (nextKey != null) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 'Home':
|
|
109
|
+
if (delegate.getFirstKey) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $ee0bdf4faa47f2a8$exports.isCtrlKeyPressed)(e));
|
|
112
|
+
manager.setFocusedKey(firstKey);
|
|
113
|
+
if ((0, $ee0bdf4faa47f2a8$exports.isCtrlKeyPressed)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
|
|
114
|
+
else if (selectOnFocus) manager.replaceSelection(firstKey);
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case 'End':
|
|
118
|
+
if (delegate.getLastKey) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
let lastKey = delegate.getLastKey(manager.focusedKey, (0, $ee0bdf4faa47f2a8$exports.isCtrlKeyPressed)(e));
|
|
121
|
+
manager.setFocusedKey(lastKey);
|
|
122
|
+
if ((0, $ee0bdf4faa47f2a8$exports.isCtrlKeyPressed)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
|
|
123
|
+
else if (selectOnFocus) manager.replaceSelection(lastKey);
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case 'PageDown':
|
|
127
|
+
if (delegate.getKeyPageBelow) {
|
|
128
|
+
let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
|
|
129
|
+
if (nextKey != null) {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
navigateToKey(nextKey);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case 'PageUp':
|
|
136
|
+
if (delegate.getKeyPageAbove) {
|
|
137
|
+
let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
|
|
138
|
+
if (nextKey != null) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
navigateToKey(nextKey);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case 'a':
|
|
145
|
+
if ((0, $ee0bdf4faa47f2a8$exports.isCtrlKeyPressed)(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
manager.selectAll();
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case 'Escape':
|
|
151
|
+
if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
manager.clearSelection();
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case 'Tab':
|
|
158
|
+
if (!allowsTabNavigation) {
|
|
159
|
+
// There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
|
|
160
|
+
// However, collections should be treated as a single tab stop, with arrow key navigation internally.
|
|
161
|
+
// We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
|
|
162
|
+
// Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
|
|
163
|
+
// in the collection, so that the browser default behavior will apply starting from that element
|
|
164
|
+
// rather than the currently focused one.
|
|
165
|
+
if (e.shiftKey) ref.current.focus();
|
|
166
|
+
else {
|
|
167
|
+
let walker = (0, $bT8Bh$reactariafocus.getFocusableTreeWalker)(ref.current, {
|
|
168
|
+
tabbable: true
|
|
169
|
+
});
|
|
170
|
+
let next;
|
|
171
|
+
let last;
|
|
172
|
+
do {
|
|
173
|
+
last = walker.lastChild();
|
|
174
|
+
if (last) next = last;
|
|
175
|
+
}while (last);
|
|
176
|
+
if (next && !next.contains(document.activeElement)) (0, $bT8Bh$reactariautils.focusWithoutScrolling)(next);
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
// Store the scroll position so we can restore it later.
|
|
183
|
+
/// TODO: should this happen all the time??
|
|
184
|
+
let scrollPos = (0, $bT8Bh$react.useRef)({
|
|
185
|
+
top: 0,
|
|
186
|
+
left: 0
|
|
187
|
+
});
|
|
188
|
+
(0, $bT8Bh$reactariautils.useEvent)(scrollRef, 'scroll', isVirtualized ? null : ()=>{
|
|
189
|
+
scrollPos.current = {
|
|
190
|
+
top: scrollRef.current.scrollTop,
|
|
191
|
+
left: scrollRef.current.scrollLeft
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
let onFocus = (e)=>{
|
|
195
|
+
if (manager.isFocused) {
|
|
196
|
+
// If a focus event bubbled through a portal, reset focus state.
|
|
197
|
+
if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// Focus events can bubble through portals. Ignore these events.
|
|
201
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
202
|
+
manager.setFocused(true);
|
|
203
|
+
if (manager.focusedKey == null) {
|
|
204
|
+
let navigateToFirstKey = (key)=>{
|
|
205
|
+
if (key != null) {
|
|
206
|
+
manager.setFocusedKey(key);
|
|
207
|
+
if (selectOnFocus) manager.replaceSelection(key);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
// If the user hasn't yet interacted with the collection, there will be no focusedKey set.
|
|
211
|
+
// Attempt to detect whether the user is tabbing forward or backward into the collection
|
|
212
|
+
// and either focus the first or last item accordingly.
|
|
213
|
+
let relatedTarget = e.relatedTarget;
|
|
214
|
+
var _manager_lastSelectedKey, _manager_firstSelectedKey;
|
|
215
|
+
if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : delegate.getLastKey());
|
|
216
|
+
else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : delegate.getFirstKey());
|
|
217
|
+
} else if (!isVirtualized) {
|
|
218
|
+
// Restore the scroll position to what it was before.
|
|
219
|
+
scrollRef.current.scrollTop = scrollPos.current.top;
|
|
220
|
+
scrollRef.current.scrollLeft = scrollPos.current.left;
|
|
221
|
+
}
|
|
222
|
+
if (manager.focusedKey != null) {
|
|
223
|
+
// Refocus and scroll the focused item into view if it exists within the scrollable region.
|
|
224
|
+
let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
|
|
225
|
+
if (element) {
|
|
226
|
+
// This prevents a flash of focus on the first/last element in the collection, or the collection itself.
|
|
227
|
+
if (!element.contains(document.activeElement)) (0, $bT8Bh$reactariautils.focusWithoutScrolling)(element);
|
|
228
|
+
let modality = (0, $bT8Bh$reactariainteractions.getInteractionModality)();
|
|
229
|
+
if (modality === 'keyboard') (0, $bT8Bh$reactariautils.scrollIntoViewport)(element, {
|
|
230
|
+
containingElement: ref.current
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
let onBlur = (e)=>{
|
|
236
|
+
// Don't set blurred and then focused again if moving focus within the collection.
|
|
237
|
+
if (!e.currentTarget.contains(e.relatedTarget)) manager.setFocused(false);
|
|
238
|
+
};
|
|
239
|
+
const autoFocusRef = (0, $bT8Bh$react.useRef)(autoFocus);
|
|
240
|
+
(0, $bT8Bh$react.useEffect)(()=>{
|
|
241
|
+
if (autoFocusRef.current) {
|
|
242
|
+
let focusedKey = null;
|
|
243
|
+
// Check focus strategy to determine which item to focus
|
|
244
|
+
if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
|
|
245
|
+
if (autoFocus === 'last') focusedKey = delegate.getLastKey();
|
|
246
|
+
// If there are any selected keys, make the first one the new focus target
|
|
247
|
+
let selectedKeys = manager.selectedKeys;
|
|
248
|
+
if (selectedKeys.size) {
|
|
249
|
+
for (let key of selectedKeys)if (manager.canSelectItem(key)) {
|
|
250
|
+
focusedKey = key;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
manager.setFocused(true);
|
|
255
|
+
manager.setFocusedKey(focusedKey);
|
|
256
|
+
// If no default focus key is selected, focus the collection itself.
|
|
257
|
+
if (focusedKey == null && !shouldUseVirtualFocus) (0, $bT8Bh$reactariafocus.focusSafely)(ref.current);
|
|
258
|
+
}
|
|
259
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
260
|
+
}, []);
|
|
261
|
+
// Scroll the focused element into view when the focusedKey changes.
|
|
262
|
+
let lastFocusedKey = (0, $bT8Bh$react.useRef)(manager.focusedKey);
|
|
263
|
+
(0, $bT8Bh$react.useEffect)(()=>{
|
|
264
|
+
if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
|
|
265
|
+
let modality = (0, $bT8Bh$reactariainteractions.getInteractionModality)();
|
|
266
|
+
let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
|
|
267
|
+
if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
|
|
268
|
+
// The collection may initially be empty (e.g. virtualizer), so wait until the element exists.
|
|
269
|
+
return;
|
|
270
|
+
if (modality === 'keyboard' || autoFocusRef.current) {
|
|
271
|
+
(0, $bT8Bh$reactariautils.scrollIntoView)(scrollRef.current, element);
|
|
272
|
+
// Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)
|
|
273
|
+
if (modality !== 'virtual') (0, $bT8Bh$reactariautils.scrollIntoViewport)(element, {
|
|
274
|
+
containingElement: ref.current
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.
|
|
279
|
+
if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $bT8Bh$reactariafocus.focusSafely)(ref.current);
|
|
280
|
+
lastFocusedKey.current = manager.focusedKey;
|
|
281
|
+
autoFocusRef.current = false;
|
|
282
|
+
});
|
|
283
|
+
// Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.
|
|
284
|
+
(0, $bT8Bh$reactariautils.useEvent)(ref, 'react-aria-focus-scope-restore', (e)=>{
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
manager.setFocused(true);
|
|
287
|
+
});
|
|
288
|
+
let handlers = {
|
|
289
|
+
onKeyDown: onKeyDown,
|
|
290
|
+
onFocus: onFocus,
|
|
291
|
+
onBlur: onBlur,
|
|
292
|
+
onMouseDown (e) {
|
|
293
|
+
// Ignore events that bubbled through portals.
|
|
294
|
+
if (scrollRef.current === e.target) // Prevent focus going to the collection when clicking on the scrollbar.
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
let { typeSelectProps: typeSelectProps } = (0, $a1189052f36475e8$exports.useTypeSelect)({
|
|
299
|
+
keyboardDelegate: delegate,
|
|
300
|
+
selectionManager: manager
|
|
301
|
+
});
|
|
302
|
+
if (!disallowTypeAhead) handlers = (0, $bT8Bh$reactariautils.mergeProps)(typeSelectProps, handlers);
|
|
303
|
+
// If nothing is focused within the collection, make the collection itself tabbable.
|
|
304
|
+
// This will be marshalled to either the first or last item depending on where focus came from.
|
|
305
|
+
// If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
|
|
306
|
+
// to move real DOM focus to the element anyway.
|
|
307
|
+
let tabIndex;
|
|
308
|
+
if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
|
|
309
|
+
return {
|
|
310
|
+
collectionProps: {
|
|
311
|
+
...handlers,
|
|
312
|
+
tabIndex: tabIndex
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
//# sourceMappingURL=useSelectableCollection.main.js.map
|