@react-aria/selection 3.20.1 → 3.21.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.
Files changed (33) hide show
  1. package/dist/DOMLayoutDelegate.main.js +9 -6
  2. package/dist/DOMLayoutDelegate.main.js.map +1 -1
  3. package/dist/DOMLayoutDelegate.mjs +9 -6
  4. package/dist/DOMLayoutDelegate.module.js +9 -6
  5. package/dist/DOMLayoutDelegate.module.js.map +1 -1
  6. package/dist/ListKeyboardDelegate.main.js +38 -30
  7. package/dist/ListKeyboardDelegate.main.js.map +1 -1
  8. package/dist/ListKeyboardDelegate.mjs +38 -30
  9. package/dist/ListKeyboardDelegate.module.js +38 -30
  10. package/dist/ListKeyboardDelegate.module.js.map +1 -1
  11. package/dist/types.d.ts +12 -12
  12. package/dist/types.d.ts.map +1 -1
  13. package/dist/useSelectableCollection.main.js +37 -25
  14. package/dist/useSelectableCollection.main.js.map +1 -1
  15. package/dist/useSelectableCollection.mjs +37 -25
  16. package/dist/useSelectableCollection.module.js +37 -25
  17. package/dist/useSelectableCollection.module.js.map +1 -1
  18. package/dist/useSelectableItem.main.js +5 -5
  19. package/dist/useSelectableItem.main.js.map +1 -1
  20. package/dist/useSelectableItem.mjs +5 -5
  21. package/dist/useSelectableItem.module.js +5 -5
  22. package/dist/useSelectableItem.module.js.map +1 -1
  23. package/dist/useTypeSelect.main.js +12 -10
  24. package/dist/useTypeSelect.main.js.map +1 -1
  25. package/dist/useTypeSelect.mjs +12 -10
  26. package/dist/useTypeSelect.module.js +12 -10
  27. package/dist/useTypeSelect.module.js.map +1 -1
  28. package/package.json +10 -10
  29. package/src/DOMLayoutDelegate.ts +11 -8
  30. package/src/ListKeyboardDelegate.ts +46 -34
  31. package/src/useSelectableCollection.ts +38 -32
  32. package/src/useSelectableItem.ts +7 -7
  33. package/src/useTypeSelect.ts +16 -14
@@ -31,21 +31,23 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
33
33
  let onKeyDown = (e)=>{
34
+ var _ref_current;
34
35
  // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
35
36
  if (e.altKey && e.key === 'Tab') e.preventDefault();
36
37
  // Keyboard events bubble through portals. Don't handle keyboard events
37
38
  // for elements outside the collection (e.g. menus).
38
- if (!ref.current.contains(e.target)) return;
39
+ if (!((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(e.target))) return;
39
40
  const navigateToKey = (key, childFocus)=>{
40
41
  if (key != null) {
41
42
  if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
43
+ var _scrollRef_current;
42
44
  // Set focused key and re-render synchronously to bring item into view if needed.
43
45
  (0, $3H3GQ$flushSync)(()=>{
44
46
  manager.setFocusedKey(key, childFocus);
45
47
  });
46
- let item = scrollRef.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
48
+ let item = (_scrollRef_current = scrollRef.current) === null || _scrollRef_current === void 0 ? void 0 : _scrollRef_current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
47
49
  let itemProps = manager.getItemProps(key);
48
- router.open(item, e, itemProps.href, itemProps.routerOptions);
50
+ if (item) router.open(item, e, itemProps.href, itemProps.routerOptions);
49
51
  return;
50
52
  }
51
53
  manager.setFocusedKey(key, childFocus);
@@ -80,7 +82,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
80
82
  case 'ArrowLeft':
81
83
  if (delegate.getKeyLeftOf) {
82
84
  var _delegate_getKeyLeftOf, _delegate_getFirstKey2, _delegate_getLastKey2;
83
- let nextKey = (_delegate_getKeyLeftOf = delegate.getKeyLeftOf) === null || _delegate_getKeyLeftOf === void 0 ? void 0 : _delegate_getKeyLeftOf.call(delegate, manager.focusedKey);
85
+ let nextKey = manager.focusedKey != null ? (_delegate_getKeyLeftOf = delegate.getKeyLeftOf) === null || _delegate_getKeyLeftOf === void 0 ? void 0 : _delegate_getKeyLeftOf.call(delegate, manager.focusedKey) : null;
84
86
  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);
85
87
  if (nextKey != null) {
86
88
  e.preventDefault();
@@ -91,7 +93,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
91
93
  case 'ArrowRight':
92
94
  if (delegate.getKeyRightOf) {
93
95
  var _delegate_getKeyRightOf, _delegate_getLastKey3, _delegate_getFirstKey3;
94
- let nextKey = (_delegate_getKeyRightOf = delegate.getKeyRightOf) === null || _delegate_getKeyRightOf === void 0 ? void 0 : _delegate_getKeyRightOf.call(delegate, manager.focusedKey);
96
+ let nextKey = manager.focusedKey != null ? (_delegate_getKeyRightOf = delegate.getKeyRightOf) === null || _delegate_getKeyRightOf === void 0 ? void 0 : _delegate_getKeyRightOf.call(delegate, manager.focusedKey) : null;
95
97
  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);
96
98
  if (nextKey != null) {
97
99
  e.preventDefault();
@@ -104,8 +106,10 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
104
106
  e.preventDefault();
105
107
  let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
106
108
  manager.setFocusedKey(firstKey);
107
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
108
- else if (selectOnFocus) manager.replaceSelection(firstKey);
109
+ if (firstKey != null) {
110
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
111
+ else if (selectOnFocus) manager.replaceSelection(firstKey);
112
+ }
109
113
  }
110
114
  break;
111
115
  case 'End':
@@ -113,12 +117,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
113
117
  e.preventDefault();
114
118
  let lastKey = delegate.getLastKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
115
119
  manager.setFocusedKey(lastKey);
116
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
117
- else if (selectOnFocus) manager.replaceSelection(lastKey);
120
+ if (lastKey != null) {
121
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
122
+ else if (selectOnFocus) manager.replaceSelection(lastKey);
123
+ }
118
124
  }
119
125
  break;
120
126
  case 'PageDown':
121
- if (delegate.getKeyPageBelow) {
127
+ if (delegate.getKeyPageBelow && manager.focusedKey != null) {
122
128
  let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
123
129
  if (nextKey != null) {
124
130
  e.preventDefault();
@@ -127,7 +133,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
127
133
  }
128
134
  break;
129
135
  case 'PageUp':
130
- if (delegate.getKeyPageAbove) {
136
+ if (delegate.getKeyPageAbove && manager.focusedKey != null) {
131
137
  let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
132
138
  if (nextKey != null) {
133
139
  e.preventDefault();
@@ -161,7 +167,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
161
167
  let walker = (0, $3H3GQ$getFocusableTreeWalker)(ref.current, {
162
168
  tabbable: true
163
169
  });
164
- let next;
170
+ let next = undefined;
165
171
  let last;
166
172
  do {
167
173
  last = walker.lastChild();
@@ -179,10 +185,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
179
185
  top: 0,
180
186
  left: 0
181
187
  });
182
- (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? null : ()=>{
188
+ (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? undefined : ()=>{
189
+ var _scrollRef_current, _scrollRef_current1;
190
+ var _scrollRef_current_scrollTop, _scrollRef_current_scrollLeft;
183
191
  scrollPos.current = {
184
- top: scrollRef.current.scrollTop,
185
- left: scrollRef.current.scrollLeft
192
+ top: (_scrollRef_current_scrollTop = (_scrollRef_current = scrollRef.current) === null || _scrollRef_current === void 0 ? void 0 : _scrollRef_current.scrollTop) !== null && _scrollRef_current_scrollTop !== void 0 ? _scrollRef_current_scrollTop : 0,
193
+ left: (_scrollRef_current_scrollLeft = (_scrollRef_current1 = scrollRef.current) === null || _scrollRef_current1 === void 0 ? void 0 : _scrollRef_current1.scrollLeft) !== null && _scrollRef_current_scrollLeft !== void 0 ? _scrollRef_current_scrollLeft : 0
186
194
  };
187
195
  });
188
196
  let onFocus = (e)=>{
@@ -195,6 +203,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
195
203
  if (!e.currentTarget.contains(e.target)) return;
196
204
  manager.setFocused(true);
197
205
  if (manager.focusedKey == null) {
206
+ var _delegate_getLastKey, _delegate_getFirstKey;
198
207
  let navigateToFirstKey = (key)=>{
199
208
  if (key != null) {
200
209
  manager.setFocusedKey(key);
@@ -206,14 +215,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
206
215
  // and either focus the first or last item accordingly.
207
216
  let relatedTarget = e.relatedTarget;
208
217
  var _manager_lastSelectedKey, _manager_firstSelectedKey;
209
- if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : delegate.getLastKey());
210
- else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : delegate.getFirstKey());
211
- } else if (!isVirtualized) {
218
+ if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate));
219
+ else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate));
220
+ } else if (!isVirtualized && scrollRef.current) {
212
221
  // Restore the scroll position to what it was before.
213
222
  scrollRef.current.scrollTop = scrollPos.current.top;
214
223
  scrollRef.current.scrollLeft = scrollPos.current.left;
215
224
  }
216
- if (manager.focusedKey != null) {
225
+ if (manager.focusedKey != null && scrollRef.current) {
217
226
  // Refocus and scroll the focused item into view if it exists within the scrollable region.
218
227
  let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
219
228
  if (element) {
@@ -233,10 +242,13 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
233
242
  const autoFocusRef = (0, $3H3GQ$useRef)(autoFocus);
234
243
  (0, $3H3GQ$useEffect)(()=>{
235
244
  if (autoFocusRef.current) {
245
+ var _delegate_getFirstKey, _delegate_getLastKey;
236
246
  let focusedKey = null;
247
+ var _delegate_getFirstKey1;
237
248
  // Check focus strategy to determine which item to focus
238
- if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
239
- if (autoFocus === 'last') focusedKey = delegate.getLastKey();
249
+ if (autoFocus === 'first') focusedKey = (_delegate_getFirstKey1 = (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate)) !== null && _delegate_getFirstKey1 !== void 0 ? _delegate_getFirstKey1 : null;
250
+ var _delegate_getLastKey1;
251
+ if (autoFocus === 'last') focusedKey = (_delegate_getLastKey1 = (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate)) !== null && _delegate_getLastKey1 !== void 0 ? _delegate_getLastKey1 : null;
240
252
  // If there are any selected keys, make the first one the new focus target
241
253
  let selectedKeys = manager.selectedKeys;
242
254
  if (selectedKeys.size) {
@@ -248,14 +260,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
248
260
  manager.setFocused(true);
249
261
  manager.setFocusedKey(focusedKey);
250
262
  // If no default focus key is selected, focus the collection itself.
251
- if (focusedKey == null && !shouldUseVirtualFocus) (0, $3H3GQ$focusSafely)(ref.current);
263
+ if (focusedKey == null && !shouldUseVirtualFocus && ref.current) (0, $3H3GQ$focusSafely)(ref.current);
252
264
  }
253
265
  // eslint-disable-next-line react-hooks/exhaustive-deps
254
266
  }, []);
255
267
  // Scroll the focused element into view when the focusedKey changes.
256
268
  let lastFocusedKey = (0, $3H3GQ$useRef)(manager.focusedKey);
257
269
  (0, $3H3GQ$useEffect)(()=>{
258
- if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
270
+ if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && scrollRef.current && ref.current) {
259
271
  let modality = (0, $3H3GQ$getInteractionModality)();
260
272
  let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
261
273
  if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
@@ -270,7 +282,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
270
282
  }
271
283
  }
272
284
  // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.
273
- if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $3H3GQ$focusSafely)(ref.current);
285
+ if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) (0, $3H3GQ$focusSafely)(ref.current);
274
286
  lastFocusedKey.current = manager.focusedKey;
275
287
  autoFocusRef.current = false;
276
288
  });
@@ -298,7 +310,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
298
310
  // This will be marshalled to either the first or last item depending on where focus came from.
299
311
  // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
300
312
  // to move real DOM focus to the element anyway.
301
- let tabIndex;
313
+ let tabIndex = undefined;
302
314
  if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
303
315
  return {
304
316
  collectionProps: {
@@ -31,21 +31,23 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
33
33
  let onKeyDown = (e)=>{
34
+ var _ref_current;
34
35
  // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
35
36
  if (e.altKey && e.key === 'Tab') e.preventDefault();
36
37
  // Keyboard events bubble through portals. Don't handle keyboard events
37
38
  // for elements outside the collection (e.g. menus).
38
- if (!ref.current.contains(e.target)) return;
39
+ if (!((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.contains(e.target))) return;
39
40
  const navigateToKey = (key, childFocus)=>{
40
41
  if (key != null) {
41
42
  if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
43
+ var _scrollRef_current;
42
44
  // Set focused key and re-render synchronously to bring item into view if needed.
43
45
  (0, $3H3GQ$flushSync)(()=>{
44
46
  manager.setFocusedKey(key, childFocus);
45
47
  });
46
- let item = scrollRef.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
48
+ let item = (_scrollRef_current = scrollRef.current) === null || _scrollRef_current === void 0 ? void 0 : _scrollRef_current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`);
47
49
  let itemProps = manager.getItemProps(key);
48
- router.open(item, e, itemProps.href, itemProps.routerOptions);
50
+ if (item) router.open(item, e, itemProps.href, itemProps.routerOptions);
49
51
  return;
50
52
  }
51
53
  manager.setFocusedKey(key, childFocus);
@@ -80,7 +82,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
80
82
  case 'ArrowLeft':
81
83
  if (delegate.getKeyLeftOf) {
82
84
  var _delegate_getKeyLeftOf, _delegate_getFirstKey2, _delegate_getLastKey2;
83
- let nextKey = (_delegate_getKeyLeftOf = delegate.getKeyLeftOf) === null || _delegate_getKeyLeftOf === void 0 ? void 0 : _delegate_getKeyLeftOf.call(delegate, manager.focusedKey);
85
+ let nextKey = manager.focusedKey != null ? (_delegate_getKeyLeftOf = delegate.getKeyLeftOf) === null || _delegate_getKeyLeftOf === void 0 ? void 0 : _delegate_getKeyLeftOf.call(delegate, manager.focusedKey) : null;
84
86
  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);
85
87
  if (nextKey != null) {
86
88
  e.preventDefault();
@@ -91,7 +93,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
91
93
  case 'ArrowRight':
92
94
  if (delegate.getKeyRightOf) {
93
95
  var _delegate_getKeyRightOf, _delegate_getLastKey3, _delegate_getFirstKey3;
94
- let nextKey = (_delegate_getKeyRightOf = delegate.getKeyRightOf) === null || _delegate_getKeyRightOf === void 0 ? void 0 : _delegate_getKeyRightOf.call(delegate, manager.focusedKey);
96
+ let nextKey = manager.focusedKey != null ? (_delegate_getKeyRightOf = delegate.getKeyRightOf) === null || _delegate_getKeyRightOf === void 0 ? void 0 : _delegate_getKeyRightOf.call(delegate, manager.focusedKey) : null;
95
97
  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);
96
98
  if (nextKey != null) {
97
99
  e.preventDefault();
@@ -104,8 +106,10 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
104
106
  e.preventDefault();
105
107
  let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
106
108
  manager.setFocusedKey(firstKey);
107
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
108
- else if (selectOnFocus) manager.replaceSelection(firstKey);
109
+ if (firstKey != null) {
110
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
111
+ else if (selectOnFocus) manager.replaceSelection(firstKey);
112
+ }
109
113
  }
110
114
  break;
111
115
  case 'End':
@@ -113,12 +117,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
113
117
  e.preventDefault();
114
118
  let lastKey = delegate.getLastKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
115
119
  manager.setFocusedKey(lastKey);
116
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
117
- else if (selectOnFocus) manager.replaceSelection(lastKey);
120
+ if (lastKey != null) {
121
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
122
+ else if (selectOnFocus) manager.replaceSelection(lastKey);
123
+ }
118
124
  }
119
125
  break;
120
126
  case 'PageDown':
121
- if (delegate.getKeyPageBelow) {
127
+ if (delegate.getKeyPageBelow && manager.focusedKey != null) {
122
128
  let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
123
129
  if (nextKey != null) {
124
130
  e.preventDefault();
@@ -127,7 +133,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
127
133
  }
128
134
  break;
129
135
  case 'PageUp':
130
- if (delegate.getKeyPageAbove) {
136
+ if (delegate.getKeyPageAbove && manager.focusedKey != null) {
131
137
  let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
132
138
  if (nextKey != null) {
133
139
  e.preventDefault();
@@ -161,7 +167,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
161
167
  let walker = (0, $3H3GQ$getFocusableTreeWalker)(ref.current, {
162
168
  tabbable: true
163
169
  });
164
- let next;
170
+ let next = undefined;
165
171
  let last;
166
172
  do {
167
173
  last = walker.lastChild();
@@ -179,10 +185,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
179
185
  top: 0,
180
186
  left: 0
181
187
  });
182
- (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? null : ()=>{
188
+ (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? undefined : ()=>{
189
+ var _scrollRef_current, _scrollRef_current1;
190
+ var _scrollRef_current_scrollTop, _scrollRef_current_scrollLeft;
183
191
  scrollPos.current = {
184
- top: scrollRef.current.scrollTop,
185
- left: scrollRef.current.scrollLeft
192
+ top: (_scrollRef_current_scrollTop = (_scrollRef_current = scrollRef.current) === null || _scrollRef_current === void 0 ? void 0 : _scrollRef_current.scrollTop) !== null && _scrollRef_current_scrollTop !== void 0 ? _scrollRef_current_scrollTop : 0,
193
+ left: (_scrollRef_current_scrollLeft = (_scrollRef_current1 = scrollRef.current) === null || _scrollRef_current1 === void 0 ? void 0 : _scrollRef_current1.scrollLeft) !== null && _scrollRef_current_scrollLeft !== void 0 ? _scrollRef_current_scrollLeft : 0
186
194
  };
187
195
  });
188
196
  let onFocus = (e)=>{
@@ -195,6 +203,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
195
203
  if (!e.currentTarget.contains(e.target)) return;
196
204
  manager.setFocused(true);
197
205
  if (manager.focusedKey == null) {
206
+ var _delegate_getLastKey, _delegate_getFirstKey;
198
207
  let navigateToFirstKey = (key)=>{
199
208
  if (key != null) {
200
209
  manager.setFocusedKey(key);
@@ -206,14 +215,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
206
215
  // and either focus the first or last item accordingly.
207
216
  let relatedTarget = e.relatedTarget;
208
217
  var _manager_lastSelectedKey, _manager_firstSelectedKey;
209
- if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : delegate.getLastKey());
210
- else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : delegate.getFirstKey());
211
- } else if (!isVirtualized) {
218
+ if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey((_manager_lastSelectedKey = manager.lastSelectedKey) !== null && _manager_lastSelectedKey !== void 0 ? _manager_lastSelectedKey : (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate));
219
+ else navigateToFirstKey((_manager_firstSelectedKey = manager.firstSelectedKey) !== null && _manager_firstSelectedKey !== void 0 ? _manager_firstSelectedKey : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate));
220
+ } else if (!isVirtualized && scrollRef.current) {
212
221
  // Restore the scroll position to what it was before.
213
222
  scrollRef.current.scrollTop = scrollPos.current.top;
214
223
  scrollRef.current.scrollLeft = scrollPos.current.left;
215
224
  }
216
- if (manager.focusedKey != null) {
225
+ if (manager.focusedKey != null && scrollRef.current) {
217
226
  // Refocus and scroll the focused item into view if it exists within the scrollable region.
218
227
  let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
219
228
  if (element) {
@@ -233,10 +242,13 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
233
242
  const autoFocusRef = (0, $3H3GQ$useRef)(autoFocus);
234
243
  (0, $3H3GQ$useEffect)(()=>{
235
244
  if (autoFocusRef.current) {
245
+ var _delegate_getFirstKey, _delegate_getLastKey;
236
246
  let focusedKey = null;
247
+ var _delegate_getFirstKey1;
237
248
  // Check focus strategy to determine which item to focus
238
- if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
239
- if (autoFocus === 'last') focusedKey = delegate.getLastKey();
249
+ if (autoFocus === 'first') focusedKey = (_delegate_getFirstKey1 = (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate)) !== null && _delegate_getFirstKey1 !== void 0 ? _delegate_getFirstKey1 : null;
250
+ var _delegate_getLastKey1;
251
+ if (autoFocus === 'last') focusedKey = (_delegate_getLastKey1 = (_delegate_getLastKey = delegate.getLastKey) === null || _delegate_getLastKey === void 0 ? void 0 : _delegate_getLastKey.call(delegate)) !== null && _delegate_getLastKey1 !== void 0 ? _delegate_getLastKey1 : null;
240
252
  // If there are any selected keys, make the first one the new focus target
241
253
  let selectedKeys = manager.selectedKeys;
242
254
  if (selectedKeys.size) {
@@ -248,14 +260,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
248
260
  manager.setFocused(true);
249
261
  manager.setFocusedKey(focusedKey);
250
262
  // If no default focus key is selected, focus the collection itself.
251
- if (focusedKey == null && !shouldUseVirtualFocus) (0, $3H3GQ$focusSafely)(ref.current);
263
+ if (focusedKey == null && !shouldUseVirtualFocus && ref.current) (0, $3H3GQ$focusSafely)(ref.current);
252
264
  }
253
265
  // eslint-disable-next-line react-hooks/exhaustive-deps
254
266
  }, []);
255
267
  // Scroll the focused element into view when the focusedKey changes.
256
268
  let lastFocusedKey = (0, $3H3GQ$useRef)(manager.focusedKey);
257
269
  (0, $3H3GQ$useEffect)(()=>{
258
- if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
270
+ if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && scrollRef.current && ref.current) {
259
271
  let modality = (0, $3H3GQ$getInteractionModality)();
260
272
  let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
261
273
  if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
@@ -270,7 +282,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
270
282
  }
271
283
  }
272
284
  // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.
273
- if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $3H3GQ$focusSafely)(ref.current);
285
+ if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) (0, $3H3GQ$focusSafely)(ref.current);
274
286
  lastFocusedKey.current = manager.focusedKey;
275
287
  autoFocusRef.current = false;
276
288
  });
@@ -298,7 +310,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
298
310
  // This will be marshalled to either the first or last item depending on where focus came from.
299
311
  // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
300
312
  // to move real DOM focus to the element anyway.
301
- let tabIndex;
313
+ let tabIndex = undefined;
302
314
  if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
303
315
  return {
304
316
  collectionProps: {
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA2FM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,sBACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,sBACtB,aAAa,aACb,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,gBAAQ;IAErB,IAAI,YAAY,CAAC;QACf,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAChC;QAGF,MAAM,gBAAgB,CAAC,KAAsB;YAC3C,IAAI,OAAO,MAAM;gBACf,IAAI,QAAQ,MAAM,CAAC,QAAQ,iBAAiB,eAAe,iBAAiB,CAAC,CAAA,G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F,CAAA,GAAA,eAAO,EAAE,KAAK,kCAAkC,CAAA;QAC9C,EAAE,cAAc;QAChB,QAAQ,UAAU,CAAC;IACrB;IAEA,IAAI,WAAW;mBACb;iBACA;gBACA;QACA,aAAY,CAAC;YACX,8CAA8C;YAC9C,IAAI,UAAU,OAAO,KAAK,EAAE,MAAM,EAChC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,yCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,8FAA8F;IAC9F,gDAAgD;IAChD,IAAI;IACJ,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,OAAO;QACL,iBAAiB;YACf,GAAG,QAAQ;sBACX;QACF;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter} from '@react-aria/utils';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`);\n let itemProps = manager.getItemProps(key);\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey = delegate.getKeyLeftOf?.(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey = delegate.getKeyRightOf?.(manager.focusedKey);\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? null : () => {\n scrollPos.current = {\n top: scrollRef.current.scrollTop,\n left: scrollRef.current.scrollLeft\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n let navigateToFirstKey = (key: Key | undefined) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());\n } else {\n navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());\n }\n } else if (!isVirtualized) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement)) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey();\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey();\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus) {\n focusSafely(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && scrollRef?.current) {\n let modality = getInteractionModality();\n let element = ref.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (!element) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || autoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n autoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA2FM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,sBACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,sBACtB,aAAa,aACb,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,gBAAQ;IAErB,IAAI,YAAY,CAAC;YAQV;QAPL,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,GAAC,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,QAAQ,CAAC,EAAE,MAAM,IACjC;QAGF,MAAM,gBAAgB,CAAC,KAAsB;YAC3C,IAAI,OAAO,MAAM;gBACf,IAAI,QAAQ,MAAM,CAAC,QAAQ,iBAAiB,eAAe,iBAAiB,CAAC,CAAA,GAAA,yCAA+B,EAA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AO;QACL,iBAAiB;YACf,GAAG,QAAQ;sBACX;QACF;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter} from '@react-aria/utils';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current?.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = scrollRef.current?.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyLeftOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyRightOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? undefined : () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n\n if (manager.focusedKey == null) {\n let navigateToFirstKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (!isVirtualized && scrollRef.current) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement)) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n const autoFocusRef = useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n focusSafely(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = ref.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (!element) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || autoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n autoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n // to move real DOM focus to the element anyway.\n let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n return {\n collectionProps: {\n ...handlers,\n tabIndex\n }\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
@@ -33,7 +33,7 @@ function $433b1145b0781e10$export$ecf600387e221c37(options) {
33
33
  else {
34
34
  if (manager.selectionMode === 'none') return;
35
35
  if (manager.isLink(key)) {
36
- if (linkBehavior === 'selection') {
36
+ if (linkBehavior === 'selection' && ref.current) {
37
37
  let itemProps = manager.getItemProps(key);
38
38
  router.open(ref.current, e, itemProps.href, itemProps.routerOptions);
39
39
  // Always set selected keys back to what they were so that select and combobox close.
@@ -55,7 +55,7 @@ function $433b1145b0781e10$export$ecf600387e221c37(options) {
55
55
  let isFocused = key === manager.focusedKey;
56
56
  if (isFocused && manager.isFocused && !shouldUseVirtualFocus) {
57
57
  if (focus) focus();
58
- else if (document.activeElement !== ref.current) (0, $i4XHw$reactariafocus.focusSafely)(ref.current);
58
+ else if (document.activeElement !== ref.current && ref.current) (0, $i4XHw$reactariafocus.focusSafely)(ref.current);
59
59
  }
60
60
  // eslint-disable-next-line react-hooks/exhaustive-deps
61
61
  }, [
@@ -98,7 +98,7 @@ function $433b1145b0781e10$export$ecf600387e221c37(options) {
98
98
  let hadPrimaryActionOnPressStart = (0, $i4XHw$react.useRef)(false);
99
99
  let performAction = (e)=>{
100
100
  if (onAction) onAction();
101
- if (hasLinkAction) {
101
+ if (hasLinkAction && ref.current) {
102
102
  let itemProps = manager.getItemProps(key);
103
103
  router.open(ref.current, e, itemProps.href, itemProps.routerOptions);
104
104
  }
@@ -126,10 +126,10 @@ function $433b1145b0781e10$export$ecf600387e221c37(options) {
126
126
  } else if (e.pointerType !== 'keyboard' && allowsSelection) onSelect(e);
127
127
  };
128
128
  else {
129
- itemPressProps.onPressUp = hasPrimaryAction ? null : (e)=>{
129
+ itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e)=>{
130
130
  if (e.pointerType !== 'keyboard' && allowsSelection) onSelect(e);
131
131
  };
132
- itemPressProps.onPress = hasPrimaryAction ? performAction : null;
132
+ itemPressProps.onPress = hasPrimaryAction ? performAction : undefined;
133
133
  }
134
134
  } else {
135
135
  itemPressProps.onPressStart = (e)=>{