@react-aria/selection 3.18.0 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/DOMLayoutDelegate.main.js +53 -0
  2. package/dist/DOMLayoutDelegate.main.js.map +1 -0
  3. package/dist/DOMLayoutDelegate.mjs +48 -0
  4. package/dist/DOMLayoutDelegate.module.js +48 -0
  5. package/dist/DOMLayoutDelegate.module.js.map +1 -0
  6. package/dist/ListKeyboardDelegate.main.js +51 -62
  7. package/dist/ListKeyboardDelegate.main.js.map +1 -1
  8. package/dist/ListKeyboardDelegate.mjs +52 -63
  9. package/dist/ListKeyboardDelegate.module.js +51 -62
  10. package/dist/ListKeyboardDelegate.module.js.map +1 -1
  11. package/dist/import.mjs +3 -1
  12. package/dist/main.js +3 -0
  13. package/dist/main.js.map +1 -1
  14. package/dist/module.js +3 -1
  15. package/dist/module.js.map +1 -1
  16. package/dist/types.d.ts +19 -7
  17. package/dist/types.d.ts.map +1 -1
  18. package/dist/useSelectableCollection.main.js +46 -44
  19. package/dist/useSelectableCollection.main.js.map +1 -1
  20. package/dist/useSelectableCollection.mjs +47 -45
  21. package/dist/useSelectableCollection.module.js +46 -44
  22. package/dist/useSelectableCollection.module.js.map +1 -1
  23. package/dist/useSelectableItem.main.js +25 -25
  24. package/dist/useSelectableItem.main.js.map +1 -1
  25. package/dist/useSelectableItem.mjs +26 -26
  26. package/dist/useSelectableItem.module.js +25 -25
  27. package/dist/useSelectableItem.module.js.map +1 -1
  28. package/dist/useSelectableList.main.js +6 -4
  29. package/dist/useSelectableList.main.js.map +1 -1
  30. package/dist/useSelectableList.mjs +7 -5
  31. package/dist/useSelectableList.module.js +6 -4
  32. package/dist/useSelectableList.module.js.map +1 -1
  33. package/dist/useTypeSelect.main.js +5 -5
  34. package/dist/useTypeSelect.mjs +6 -6
  35. package/dist/useTypeSelect.module.js +5 -5
  36. package/dist/utils.mjs +1 -1
  37. package/package.json +10 -10
  38. package/src/DOMLayoutDelegate.ts +57 -0
  39. package/src/ListKeyboardDelegate.ts +37 -49
  40. package/src/index.ts +1 -0
  41. package/src/useSelectableCollection.ts +26 -15
  42. package/src/useSelectableItem.ts +3 -3
  43. package/src/useSelectableList.ts +12 -4
@@ -26,19 +26,19 @@ import {useLocale as $3H3GQ$useLocale} from "@react-aria/i18n";
26
26
 
27
27
 
28
28
  function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
29
- 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
30
- scrollRef = ref, linkBehavior: linkBehavior = "action" } = options;
29
+ 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
30
+ scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
33
33
  let onKeyDown = (e)=>{
34
34
  // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
35
- if (e.altKey && e.key === "Tab") e.preventDefault();
35
+ if (e.altKey && e.key === 'Tab') e.preventDefault();
36
36
  // Keyboard events bubble through portals. Don't handle keyboard events
37
37
  // for elements outside the collection (e.g. menus).
38
38
  if (!ref.current.contains(e.target)) return;
39
39
  const navigateToKey = (key, childFocus)=>{
40
40
  if (key != null) {
41
- if (manager.isLink(key) && linkBehavior === "selection" && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
41
+ if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
42
42
  // Set focused key and re-render synchronously to bring item into view if needed.
43
43
  (0, $3H3GQ$flushSync)(()=>{
44
44
  manager.setFocusedKey(key, childFocus);
@@ -49,13 +49,13 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
49
49
  return;
50
50
  }
51
51
  manager.setFocusedKey(key, childFocus);
52
- if (manager.isLink(key) && linkBehavior === "override") return;
53
- if (e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(key);
52
+ if (manager.isLink(key) && linkBehavior === 'override') return;
53
+ if (e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(key);
54
54
  else if (selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) manager.replaceSelection(key);
55
55
  }
56
56
  };
57
57
  switch(e.key){
58
- case "ArrowDown":
58
+ case 'ArrowDown':
59
59
  if (delegate.getKeyBelow) {
60
60
  var _delegate_getFirstKey, _delegate_getFirstKey1;
61
61
  e.preventDefault();
@@ -64,7 +64,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
64
64
  navigateToKey(nextKey);
65
65
  }
66
66
  break;
67
- case "ArrowUp":
67
+ case 'ArrowUp':
68
68
  if (delegate.getKeyAbove) {
69
69
  var _delegate_getLastKey, _delegate_getLastKey1;
70
70
  e.preventDefault();
@@ -73,70 +73,70 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
73
73
  navigateToKey(nextKey);
74
74
  }
75
75
  break;
76
- case "ArrowLeft":
76
+ case 'ArrowLeft':
77
77
  if (delegate.getKeyLeftOf) {
78
78
  var _delegate_getFirstKey2, _delegate_getLastKey2;
79
79
  e.preventDefault();
80
80
  let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
81
- 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);
82
- navigateToKey(nextKey, direction === "rtl" ? "first" : "last");
81
+ 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);
82
+ navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
83
83
  }
84
84
  break;
85
- case "ArrowRight":
85
+ case 'ArrowRight':
86
86
  if (delegate.getKeyRightOf) {
87
87
  var _delegate_getLastKey3, _delegate_getFirstKey3;
88
88
  e.preventDefault();
89
89
  let nextKey = delegate.getKeyRightOf(manager.focusedKey);
90
- 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);
91
- navigateToKey(nextKey, direction === "rtl" ? "last" : "first");
90
+ 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);
91
+ navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
92
92
  }
93
93
  break;
94
- case "Home":
94
+ case 'Home':
95
95
  if (delegate.getFirstKey) {
96
96
  e.preventDefault();
97
97
  let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
98
98
  manager.setFocusedKey(firstKey);
99
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(firstKey);
99
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
100
100
  else if (selectOnFocus) manager.replaceSelection(firstKey);
101
101
  }
102
102
  break;
103
- case "End":
103
+ case 'End':
104
104
  if (delegate.getLastKey) {
105
105
  e.preventDefault();
106
106
  let lastKey = delegate.getLastKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
107
107
  manager.setFocusedKey(lastKey);
108
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(lastKey);
108
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
109
109
  else if (selectOnFocus) manager.replaceSelection(lastKey);
110
110
  }
111
111
  break;
112
- case "PageDown":
112
+ case 'PageDown':
113
113
  if (delegate.getKeyPageBelow) {
114
114
  e.preventDefault();
115
115
  let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
116
116
  navigateToKey(nextKey);
117
117
  }
118
118
  break;
119
- case "PageUp":
119
+ case 'PageUp':
120
120
  if (delegate.getKeyPageAbove) {
121
121
  e.preventDefault();
122
122
  let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
123
123
  navigateToKey(nextKey);
124
124
  }
125
125
  break;
126
- case "a":
127
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && manager.selectionMode === "multiple" && disallowSelectAll !== true) {
126
+ case 'a':
127
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
128
128
  e.preventDefault();
129
129
  manager.selectAll();
130
130
  }
131
131
  break;
132
- case "Escape":
132
+ case 'Escape':
133
133
  if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
134
134
  e.stopPropagation();
135
135
  e.preventDefault();
136
136
  manager.clearSelection();
137
137
  }
138
138
  break;
139
- case "Tab":
139
+ case 'Tab':
140
140
  if (!allowsTabNavigation) {
141
141
  // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
142
142
  // However, collections should be treated as a single tab stop, with arrow key navigation internally.
@@ -162,11 +162,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
162
162
  }
163
163
  };
164
164
  // Store the scroll position so we can restore it later.
165
+ /// TODO: should this happen all the time??
165
166
  let scrollPos = (0, $3H3GQ$useRef)({
166
167
  top: 0,
167
168
  left: 0
168
169
  });
169
- (0, $3H3GQ$useEvent)(scrollRef, "scroll", isVirtualized ? null : ()=>{
170
+ (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? null : ()=>{
170
171
  scrollPos.current = {
171
172
  top: scrollRef.current.scrollTop,
172
173
  left: scrollRef.current.scrollLeft
@@ -200,14 +201,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
200
201
  scrollRef.current.scrollTop = scrollPos.current.top;
201
202
  scrollRef.current.scrollLeft = scrollPos.current.left;
202
203
  }
203
- if (!isVirtualized && manager.focusedKey != null) {
204
+ if (manager.focusedKey != null) {
204
205
  // Refocus and scroll the focused item into view if it exists within the scrollable region.
205
206
  let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
206
207
  if (element) {
207
208
  // This prevents a flash of focus on the first/last element in the collection, or the collection itself.
208
209
  if (!element.contains(document.activeElement)) (0, $3H3GQ$focusWithoutScrolling)(element);
209
210
  let modality = (0, $3H3GQ$getInteractionModality)();
210
- if (modality === "keyboard") (0, $3H3GQ$scrollIntoViewport)(element, {
211
+ if (modality === 'keyboard') (0, $3H3GQ$scrollIntoViewport)(element, {
211
212
  containingElement: ref.current
212
213
  });
213
214
  }
@@ -222,8 +223,8 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
222
223
  if (autoFocusRef.current) {
223
224
  let focusedKey = null;
224
225
  // Check focus strategy to determine which item to focus
225
- if (autoFocus === "first") focusedKey = delegate.getFirstKey();
226
- if (autoFocus === "last") focusedKey = delegate.getLastKey();
226
+ if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
227
+ if (autoFocus === 'last') focusedKey = delegate.getLastKey();
227
228
  // If there are any selected keys, make the first one the new focus target
228
229
  let selectedKeys = manager.selectedKeys;
229
230
  if (selectedKeys.size) {
@@ -239,17 +240,19 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
239
240
  }
240
241
  // eslint-disable-next-line react-hooks/exhaustive-deps
241
242
  }, []);
242
- // If not virtualized, scroll the focused element into view when the focusedKey changes.
243
- // When virtualized, Virtualizer handles this internally.
243
+ // Scroll the focused element into view when the focusedKey changes.
244
244
  let lastFocusedKey = (0, $3H3GQ$useRef)(manager.focusedKey);
245
245
  (0, $3H3GQ$useEffect)(()=>{
246
- let modality = (0, $3H3GQ$getInteractionModality)();
247
- if (manager.isFocused && manager.focusedKey != null && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
248
- let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
249
- if (element && (modality === "keyboard" || autoFocusRef.current)) {
250
- if (!isVirtualized) (0, $3H3GQ$scrollIntoView)(scrollRef.current, element);
246
+ if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
247
+ let modality = (0, $3H3GQ$getInteractionModality)();
248
+ let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
249
+ if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
250
+ // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.
251
+ return;
252
+ if (modality === 'keyboard' || autoFocusRef.current) {
253
+ (0, $3H3GQ$scrollIntoView)(scrollRef.current, element);
251
254
  // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)
252
- if (modality !== "virtual") (0, $3H3GQ$scrollIntoViewport)(element, {
255
+ if (modality !== 'virtual') (0, $3H3GQ$scrollIntoViewport)(element, {
253
256
  containingElement: ref.current
254
257
  });
255
258
  }
@@ -258,13 +261,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
258
261
  if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $3H3GQ$focusSafely)(ref.current);
259
262
  lastFocusedKey.current = manager.focusedKey;
260
263
  autoFocusRef.current = false;
261
- }, [
262
- isVirtualized,
263
- scrollRef,
264
- manager.focusedKey,
265
- manager.isFocused,
266
- ref
267
- ]);
264
+ });
265
+ // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.
266
+ (0, $3H3GQ$useEvent)(ref, 'react-aria-focus-scope-restore', (e)=>{
267
+ e.preventDefault();
268
+ manager.setFocused(true);
269
+ });
268
270
  let handlers = {
269
271
  onKeyDown: onKeyDown,
270
272
  onFocus: onFocus,
@@ -296,4 +298,4 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
296
298
 
297
299
 
298
300
  export {$ae20dd8cbca75726$export$d6daf82dcd84e87c as useSelectableCollection};
299
- //# sourceMappingURL=useSelectableCollection.mjs.map
301
+ //# sourceMappingURL=useSelectableCollection.module.js.map
@@ -26,19 +26,19 @@ import {useLocale as $3H3GQ$useLocale} from "@react-aria/i18n";
26
26
 
27
27
 
28
28
  function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
29
- 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
30
- scrollRef = ref, linkBehavior: linkBehavior = "action" } = options;
29
+ 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
30
+ scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
33
33
  let onKeyDown = (e)=>{
34
34
  // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
35
- if (e.altKey && e.key === "Tab") e.preventDefault();
35
+ if (e.altKey && e.key === 'Tab') e.preventDefault();
36
36
  // Keyboard events bubble through portals. Don't handle keyboard events
37
37
  // for elements outside the collection (e.g. menus).
38
38
  if (!ref.current.contains(e.target)) return;
39
39
  const navigateToKey = (key, childFocus)=>{
40
40
  if (key != null) {
41
- if (manager.isLink(key) && linkBehavior === "selection" && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
41
+ if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) {
42
42
  // Set focused key and re-render synchronously to bring item into view if needed.
43
43
  (0, $3H3GQ$flushSync)(()=>{
44
44
  manager.setFocusedKey(key, childFocus);
@@ -49,13 +49,13 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
49
49
  return;
50
50
  }
51
51
  manager.setFocusedKey(key, childFocus);
52
- if (manager.isLink(key) && linkBehavior === "override") return;
53
- if (e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(key);
52
+ if (manager.isLink(key) && linkBehavior === 'override') return;
53
+ if (e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(key);
54
54
  else if (selectOnFocus && !(0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) manager.replaceSelection(key);
55
55
  }
56
56
  };
57
57
  switch(e.key){
58
- case "ArrowDown":
58
+ case 'ArrowDown':
59
59
  if (delegate.getKeyBelow) {
60
60
  var _delegate_getFirstKey, _delegate_getFirstKey1;
61
61
  e.preventDefault();
@@ -64,7 +64,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
64
64
  navigateToKey(nextKey);
65
65
  }
66
66
  break;
67
- case "ArrowUp":
67
+ case 'ArrowUp':
68
68
  if (delegate.getKeyAbove) {
69
69
  var _delegate_getLastKey, _delegate_getLastKey1;
70
70
  e.preventDefault();
@@ -73,70 +73,70 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
73
73
  navigateToKey(nextKey);
74
74
  }
75
75
  break;
76
- case "ArrowLeft":
76
+ case 'ArrowLeft':
77
77
  if (delegate.getKeyLeftOf) {
78
78
  var _delegate_getFirstKey2, _delegate_getLastKey2;
79
79
  e.preventDefault();
80
80
  let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
81
- 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);
82
- navigateToKey(nextKey, direction === "rtl" ? "first" : "last");
81
+ 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);
82
+ navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
83
83
  }
84
84
  break;
85
- case "ArrowRight":
85
+ case 'ArrowRight':
86
86
  if (delegate.getKeyRightOf) {
87
87
  var _delegate_getLastKey3, _delegate_getFirstKey3;
88
88
  e.preventDefault();
89
89
  let nextKey = delegate.getKeyRightOf(manager.focusedKey);
90
- 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);
91
- navigateToKey(nextKey, direction === "rtl" ? "last" : "first");
90
+ 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);
91
+ navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
92
92
  }
93
93
  break;
94
- case "Home":
94
+ case 'Home':
95
95
  if (delegate.getFirstKey) {
96
96
  e.preventDefault();
97
97
  let firstKey = delegate.getFirstKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
98
98
  manager.setFocusedKey(firstKey);
99
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(firstKey);
99
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
100
100
  else if (selectOnFocus) manager.replaceSelection(firstKey);
101
101
  }
102
102
  break;
103
- case "End":
103
+ case 'End':
104
104
  if (delegate.getLastKey) {
105
105
  e.preventDefault();
106
106
  let lastKey = delegate.getLastKey(manager.focusedKey, (0, $feb5ffebff200149$export$16792effe837dba3)(e));
107
107
  manager.setFocusedKey(lastKey);
108
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === "multiple") manager.extendSelection(lastKey);
108
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
109
109
  else if (selectOnFocus) manager.replaceSelection(lastKey);
110
110
  }
111
111
  break;
112
- case "PageDown":
112
+ case 'PageDown':
113
113
  if (delegate.getKeyPageBelow) {
114
114
  e.preventDefault();
115
115
  let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
116
116
  navigateToKey(nextKey);
117
117
  }
118
118
  break;
119
- case "PageUp":
119
+ case 'PageUp':
120
120
  if (delegate.getKeyPageAbove) {
121
121
  e.preventDefault();
122
122
  let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
123
123
  navigateToKey(nextKey);
124
124
  }
125
125
  break;
126
- case "a":
127
- if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && manager.selectionMode === "multiple" && disallowSelectAll !== true) {
126
+ case 'a':
127
+ if ((0, $feb5ffebff200149$export$16792effe837dba3)(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
128
128
  e.preventDefault();
129
129
  manager.selectAll();
130
130
  }
131
131
  break;
132
- case "Escape":
132
+ case 'Escape':
133
133
  if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
134
134
  e.stopPropagation();
135
135
  e.preventDefault();
136
136
  manager.clearSelection();
137
137
  }
138
138
  break;
139
- case "Tab":
139
+ case 'Tab':
140
140
  if (!allowsTabNavigation) {
141
141
  // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
142
142
  // However, collections should be treated as a single tab stop, with arrow key navigation internally.
@@ -162,11 +162,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
162
162
  }
163
163
  };
164
164
  // Store the scroll position so we can restore it later.
165
+ /// TODO: should this happen all the time??
165
166
  let scrollPos = (0, $3H3GQ$useRef)({
166
167
  top: 0,
167
168
  left: 0
168
169
  });
169
- (0, $3H3GQ$useEvent)(scrollRef, "scroll", isVirtualized ? null : ()=>{
170
+ (0, $3H3GQ$useEvent)(scrollRef, 'scroll', isVirtualized ? null : ()=>{
170
171
  scrollPos.current = {
171
172
  top: scrollRef.current.scrollTop,
172
173
  left: scrollRef.current.scrollLeft
@@ -200,14 +201,14 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
200
201
  scrollRef.current.scrollTop = scrollPos.current.top;
201
202
  scrollRef.current.scrollLeft = scrollPos.current.left;
202
203
  }
203
- if (!isVirtualized && manager.focusedKey != null) {
204
+ if (manager.focusedKey != null) {
204
205
  // Refocus and scroll the focused item into view if it exists within the scrollable region.
205
206
  let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
206
207
  if (element) {
207
208
  // This prevents a flash of focus on the first/last element in the collection, or the collection itself.
208
209
  if (!element.contains(document.activeElement)) (0, $3H3GQ$focusWithoutScrolling)(element);
209
210
  let modality = (0, $3H3GQ$getInteractionModality)();
210
- if (modality === "keyboard") (0, $3H3GQ$scrollIntoViewport)(element, {
211
+ if (modality === 'keyboard') (0, $3H3GQ$scrollIntoViewport)(element, {
211
212
  containingElement: ref.current
212
213
  });
213
214
  }
@@ -222,8 +223,8 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
222
223
  if (autoFocusRef.current) {
223
224
  let focusedKey = null;
224
225
  // Check focus strategy to determine which item to focus
225
- if (autoFocus === "first") focusedKey = delegate.getFirstKey();
226
- if (autoFocus === "last") focusedKey = delegate.getLastKey();
226
+ if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
227
+ if (autoFocus === 'last') focusedKey = delegate.getLastKey();
227
228
  // If there are any selected keys, make the first one the new focus target
228
229
  let selectedKeys = manager.selectedKeys;
229
230
  if (selectedKeys.size) {
@@ -239,17 +240,19 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
239
240
  }
240
241
  // eslint-disable-next-line react-hooks/exhaustive-deps
241
242
  }, []);
242
- // If not virtualized, scroll the focused element into view when the focusedKey changes.
243
- // When virtualized, Virtualizer handles this internally.
243
+ // Scroll the focused element into view when the focusedKey changes.
244
244
  let lastFocusedKey = (0, $3H3GQ$useRef)(manager.focusedKey);
245
245
  (0, $3H3GQ$useEffect)(()=>{
246
- let modality = (0, $3H3GQ$getInteractionModality)();
247
- if (manager.isFocused && manager.focusedKey != null && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
248
- let element = scrollRef.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
249
- if (element && (modality === "keyboard" || autoFocusRef.current)) {
250
- if (!isVirtualized) (0, $3H3GQ$scrollIntoView)(scrollRef.current, element);
246
+ if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || autoFocusRef.current) && (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
247
+ let modality = (0, $3H3GQ$getInteractionModality)();
248
+ let element = ref.current.querySelector(`[data-key="${CSS.escape(manager.focusedKey.toString())}"]`);
249
+ if (!element) // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).
250
+ // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.
251
+ return;
252
+ if (modality === 'keyboard' || autoFocusRef.current) {
253
+ (0, $3H3GQ$scrollIntoView)(scrollRef.current, element);
251
254
  // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)
252
- if (modality !== "virtual") (0, $3H3GQ$scrollIntoViewport)(element, {
255
+ if (modality !== 'virtual') (0, $3H3GQ$scrollIntoViewport)(element, {
253
256
  containingElement: ref.current
254
257
  });
255
258
  }
@@ -258,13 +261,12 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
258
261
  if (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) (0, $3H3GQ$focusSafely)(ref.current);
259
262
  lastFocusedKey.current = manager.focusedKey;
260
263
  autoFocusRef.current = false;
261
- }, [
262
- isVirtualized,
263
- scrollRef,
264
- manager.focusedKey,
265
- manager.isFocused,
266
- ref
267
- ]);
264
+ });
265
+ // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.
266
+ (0, $3H3GQ$useEvent)(ref, 'react-aria-focus-scope-restore', (e)=>{
267
+ e.preventDefault();
268
+ manager.setFocused(true);
269
+ });
268
270
  let handlers = {
269
271
  onKeyDown: onKeyDown,
270
272
  onFocus: onFocus,
@@ -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,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Aa,OAAO,GAAG;IACzB,GAAG;QAAC;QAAe;QAAW,QAAQ,UAAU;QAAE,QAAQ,SAAS;QAAE;KAAI;IAEzE,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} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, RefObject, 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>,\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>,\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 e.preventDefault();\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 navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\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 navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\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 navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\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 navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\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 e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\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 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 (!isVirtualized && 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 // If not virtualized, scroll the focused element into view when the focusedKey changes.\n // When virtualized, Virtualizer handles this internally.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n let modality = getInteractionModality();\n if (manager.isFocused && manager.focusedKey != null && scrollRef?.current) {\n let element = scrollRef.current.querySelector(`[data-key=\"${CSS.escape(manager.focusedKey.toString())}\"]`) as HTMLElement;\n if (element && (modality === 'keyboard' || autoFocusRef.current)) {\n if (!isVirtualized) {\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 (manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n autoFocusRef.current = false;\n }, [isVirtualized, scrollRef, manager.focusedKey, manager.isFocused, ref]);\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 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M,CAAC,QAAQ,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;YACnG,IAAI,CAAC,SACH,6FAA6F;YAC7F,8FAA8F;YAC9F;YAGF,IAAI,aAAa,cAAc,aAAa,OAAO,EAAE;gBACnD,CAAA,GAAA,qBAAa,EAAE,UAAU,OAAO,EAAE;gBAElC,iFAAiF;gBACjF,IAAI,aAAa,WACf,CAAA,GAAA,yBAAiB,EAAE,SAAS;oBAAC,mBAAmB,IAAI,OAAO;gBAAA;YAE/D;QACF;QAEA,+FAA+F;QAC/F,IAAI,QAAQ,SAAS,IAAI,QAAQ,UAAU,IAAI,QAAQ,eAAe,OAAO,IAAI,MAC/E,CAAA,GAAA,kBAAU,EAAE,IAAI,OAAO;QAGzB,eAAe,OAAO,GAAG,QAAQ,UAAU;QAC3C,aAAa,OAAO,GAAG;IACzB;IAEA,sFAAsF;IACtF,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 e.preventDefault();\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 navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n e.preventDefault();\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 navigateToKey(nextKey);\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n e.preventDefault();\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 navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n e.preventDefault();\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 navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\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 e.preventDefault();\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n navigateToKey(nextKey);\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove) {\n e.preventDefault();\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n navigateToKey(nextKey);\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 (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"}