@react-aria/selection 3.26.0 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelectableCollection.main.js +30 -31
- package/dist/useSelectableCollection.main.js.map +1 -1
- package/dist/useSelectableCollection.mjs +31 -32
- package/dist/useSelectableCollection.module.js +31 -32
- package/dist/useSelectableCollection.module.js.map +1 -1
- package/package.json +7 -7
- package/src/useSelectableCollection.ts +30 -34
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;ACqBA;IACE;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;;OAEG;IACH,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED;;GAEG;AACH,8BAA8B,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAyD5E;AChFD;IACE;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IACnC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;IAC9C;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE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BAA4B,CAAC,CAAC;IAkDnD,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAMhC,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAsCpC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAQjC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAYjC,aAAa,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAsBpC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAoBnC,WAAW,IAAI,GAAG,GAAG,IAAI;IAKzB,UAAU,IAAI,GAAG,GAAG,IAAI;IAKxB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IA+BrC,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IA+BrC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;CAsB3D;AChRD,0CAA2C,SAAQ,IAAI,CAAC,+BAA+B,EAAE,kBAAkB,CAAC;IAC1G;;OAEG;IACH,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED;IACE;;OAEG;IACH,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;GAEG;AACH,kCAAkC,KAAK,EAAE,yBAAyB,GAAG,kBAAkB,CAmCtF","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/DOMLayoutDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -180,7 +180,10 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
|
|
|
180
180
|
last = walker.lastChild();
|
|
181
181
|
if (last) next = last;
|
|
182
182
|
}while (last);
|
|
183
|
-
|
|
183
|
+
// If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to
|
|
184
|
+
// the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between
|
|
185
|
+
// focusing the containing cell and back to the non-tabbable child element
|
|
186
|
+
if (next && (!next.contains(document.activeElement) || document.activeElement && !(0, $bT8Bh$reactariautils.isTabbable)(document.activeElement))) (0, $bT8Bh$reactariautils.focusWithoutScrolling)(next);
|
|
184
187
|
}
|
|
185
188
|
break;
|
|
186
189
|
}
|
|
@@ -260,44 +263,40 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
|
|
|
260
263
|
// If the user is typing forwards, autofocus the first option in the list.
|
|
261
264
|
if ((detail === null || detail === void 0 ? void 0 : detail.focusStrategy) === 'first') shouldVirtualFocusFirst.current = true;
|
|
262
265
|
});
|
|
263
|
-
|
|
264
|
-
var _delegate_getFirstKey;
|
|
265
|
-
var _delegate_getFirstKey1;
|
|
266
|
-
let keyToFocus = (_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;
|
|
267
|
-
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
268
|
-
// the original active element (e.g. the autocomplete input)
|
|
269
|
-
if (keyToFocus == null) {
|
|
270
|
-
let previousActiveElement = (0, $bT8Bh$reactariautils.getActiveElement)();
|
|
271
|
-
(0, $bT8Bh$reactariafocus.moveVirtualFocus)(ref.current);
|
|
272
|
-
(0, $bT8Bh$reactariafocus.dispatchVirtualFocus)(previousActiveElement, null);
|
|
273
|
-
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
274
|
-
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
275
|
-
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
276
|
-
} else {
|
|
277
|
-
manager.setFocusedKey(keyToFocus);
|
|
278
|
-
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
279
|
-
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
280
|
-
// after the collection updates after load
|
|
281
|
-
shouldVirtualFocusFirst.current = false;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
266
|
+
// update active descendant
|
|
284
267
|
(0, $bT8Bh$reactariautils.useUpdateLayoutEffect)(()=>{
|
|
285
|
-
if (shouldVirtualFocusFirst.current)
|
|
268
|
+
if (shouldVirtualFocusFirst.current) {
|
|
269
|
+
var _delegate_getFirstKey;
|
|
270
|
+
var _delegate_getFirstKey1;
|
|
271
|
+
let keyToFocus = (_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;
|
|
272
|
+
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
273
|
+
// the original active element (e.g. the autocomplete input)
|
|
274
|
+
if (keyToFocus == null) {
|
|
275
|
+
let previousActiveElement = (0, $bT8Bh$reactariautils.getActiveElement)();
|
|
276
|
+
(0, $bT8Bh$reactariafocus.moveVirtualFocus)(ref.current);
|
|
277
|
+
(0, $bT8Bh$reactariafocus.dispatchVirtualFocus)(previousActiveElement, null);
|
|
278
|
+
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
279
|
+
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
280
|
+
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
281
|
+
} else {
|
|
282
|
+
manager.setFocusedKey(keyToFocus);
|
|
283
|
+
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
284
|
+
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
285
|
+
// after the collection updates after load
|
|
286
|
+
shouldVirtualFocusFirst.current = false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
286
289
|
}, [
|
|
287
|
-
manager.collection
|
|
288
|
-
updateActiveDescendant
|
|
290
|
+
manager.collection
|
|
289
291
|
]);
|
|
290
|
-
|
|
292
|
+
// reset focus first flag
|
|
293
|
+
(0, $bT8Bh$reactariautils.useUpdateLayoutEffect)(()=>{
|
|
291
294
|
// If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't
|
|
292
295
|
// accidentally move focus from under them. Skip this if the collection was empty because we might be in a load
|
|
293
296
|
// state and will still want to focus the first item after load
|
|
294
297
|
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
295
|
-
});
|
|
296
|
-
(0, $bT8Bh$reactariautils.useUpdateLayoutEffect)(()=>{
|
|
297
|
-
resetFocusFirstFlag();
|
|
298
298
|
}, [
|
|
299
|
-
manager.focusedKey
|
|
300
|
-
resetFocusFirstFlag
|
|
299
|
+
manager.focusedKey
|
|
301
300
|
]);
|
|
302
301
|
(0, $bT8Bh$reactariautils.useEvent)(ref, (0, $bT8Bh$reactariautils.CLEAR_FOCUS_EVENT), !shouldUseVirtualFocus ? undefined : (e)=>{
|
|
303
302
|
var _e_detail;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oBAAoB,iCACpB,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,8BAAQ;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CAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\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, getInteractionModality} from '@react-aria/interactions';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} 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 pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\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 escapeKeyBehavior = 'clearSelection',\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 = getItemElement(ref, key);\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 (escapeKeyBehavior === 'clearSelection' && !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 if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\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 navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(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 = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\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) && !shouldUseVirtualFocus) {\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 // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (keyToFocus == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\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 // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\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' || didAutoFocusRef.current) {\n\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\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 }\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 didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oBAAoB,iCACpB,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,8BAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,+BAAQ;IAErB,IAAI,YA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gCAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, isTabbable, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\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, getInteractionModality} from '@react-aria/interactions';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} 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 pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\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 escapeKeyBehavior = 'clearSelection',\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 = getItemElement(ref, key);\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 (escapeKeyBehavior === 'clearSelection' && !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 the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to\n // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between\n // focusing the containing cell and back to the non-tabbable child element\n if (next && (!next.contains(document.activeElement) || (document.activeElement && !isTabbable(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 if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\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 navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(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 = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\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) && !shouldUseVirtualFocus) {\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 // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n // update active descendant\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (keyToFocus == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n }\n }, [manager.collection]);\n\n // reset focus first flag\n useUpdateLayoutEffect(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n }, [manager.focusedKey]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\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 // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\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' || didAutoFocusRef.current) {\n\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\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 }\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 didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {getItemElement as $feb5ffebff200149$export$c3d8340acf92597f, isNonContiguousSelectionModifier as $feb5ffebff200149$export$d3e3bd3e26688c04, useCollectionId as $feb5ffebff200149$export$881eb0d9f3605d9d} from "./utils.mjs";
|
|
2
2
|
import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useTypeSelect.mjs";
|
|
3
|
-
import {useRouter as $3H3GQ$useRouter, isCtrlKeyPressed as $3H3GQ$isCtrlKeyPressed, focusWithoutScrolling as $3H3GQ$focusWithoutScrolling, useEvent as $3H3GQ$useEvent, scrollIntoViewport as $3H3GQ$scrollIntoViewport, FOCUS_EVENT as $3H3GQ$FOCUS_EVENT,
|
|
3
|
+
import {useRouter as $3H3GQ$useRouter, isCtrlKeyPressed as $3H3GQ$isCtrlKeyPressed, isTabbable as $3H3GQ$isTabbable, focusWithoutScrolling as $3H3GQ$focusWithoutScrolling, useEvent as $3H3GQ$useEvent, scrollIntoViewport as $3H3GQ$scrollIntoViewport, FOCUS_EVENT as $3H3GQ$FOCUS_EVENT, useUpdateLayoutEffect as $3H3GQ$useUpdateLayoutEffect, getActiveElement as $3H3GQ$getActiveElement, CLEAR_FOCUS_EVENT as $3H3GQ$CLEAR_FOCUS_EVENT, scrollIntoView as $3H3GQ$scrollIntoView, mergeProps as $3H3GQ$mergeProps} from "@react-aria/utils";
|
|
4
4
|
import {getFocusableTreeWalker as $3H3GQ$getFocusableTreeWalker, moveVirtualFocus as $3H3GQ$moveVirtualFocus, dispatchVirtualFocus as $3H3GQ$dispatchVirtualFocus} from "@react-aria/focus";
|
|
5
5
|
import {flushSync as $3H3GQ$flushSync} from "react-dom";
|
|
6
6
|
import {useRef as $3H3GQ$useRef, useEffect as $3H3GQ$useEffect} from "react";
|
|
@@ -174,7 +174,10 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
|
|
|
174
174
|
last = walker.lastChild();
|
|
175
175
|
if (last) next = last;
|
|
176
176
|
}while (last);
|
|
177
|
-
|
|
177
|
+
// If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to
|
|
178
|
+
// the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between
|
|
179
|
+
// focusing the containing cell and back to the non-tabbable child element
|
|
180
|
+
if (next && (!next.contains(document.activeElement) || document.activeElement && !(0, $3H3GQ$isTabbable)(document.activeElement))) (0, $3H3GQ$focusWithoutScrolling)(next);
|
|
178
181
|
}
|
|
179
182
|
break;
|
|
180
183
|
}
|
|
@@ -254,44 +257,40 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
|
|
|
254
257
|
// If the user is typing forwards, autofocus the first option in the list.
|
|
255
258
|
if ((detail === null || detail === void 0 ? void 0 : detail.focusStrategy) === 'first') shouldVirtualFocusFirst.current = true;
|
|
256
259
|
});
|
|
257
|
-
|
|
258
|
-
var _delegate_getFirstKey;
|
|
259
|
-
var _delegate_getFirstKey1;
|
|
260
|
-
let keyToFocus = (_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;
|
|
261
|
-
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
262
|
-
// the original active element (e.g. the autocomplete input)
|
|
263
|
-
if (keyToFocus == null) {
|
|
264
|
-
let previousActiveElement = (0, $3H3GQ$getActiveElement)();
|
|
265
|
-
(0, $3H3GQ$moveVirtualFocus)(ref.current);
|
|
266
|
-
(0, $3H3GQ$dispatchVirtualFocus)(previousActiveElement, null);
|
|
267
|
-
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
268
|
-
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
269
|
-
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
270
|
-
} else {
|
|
271
|
-
manager.setFocusedKey(keyToFocus);
|
|
272
|
-
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
273
|
-
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
274
|
-
// after the collection updates after load
|
|
275
|
-
shouldVirtualFocusFirst.current = false;
|
|
276
|
-
}
|
|
277
|
-
});
|
|
260
|
+
// update active descendant
|
|
278
261
|
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
279
|
-
if (shouldVirtualFocusFirst.current)
|
|
262
|
+
if (shouldVirtualFocusFirst.current) {
|
|
263
|
+
var _delegate_getFirstKey;
|
|
264
|
+
var _delegate_getFirstKey1;
|
|
265
|
+
let keyToFocus = (_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;
|
|
266
|
+
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
267
|
+
// the original active element (e.g. the autocomplete input)
|
|
268
|
+
if (keyToFocus == null) {
|
|
269
|
+
let previousActiveElement = (0, $3H3GQ$getActiveElement)();
|
|
270
|
+
(0, $3H3GQ$moveVirtualFocus)(ref.current);
|
|
271
|
+
(0, $3H3GQ$dispatchVirtualFocus)(previousActiveElement, null);
|
|
272
|
+
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
273
|
+
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
274
|
+
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
275
|
+
} else {
|
|
276
|
+
manager.setFocusedKey(keyToFocus);
|
|
277
|
+
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
278
|
+
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
279
|
+
// after the collection updates after load
|
|
280
|
+
shouldVirtualFocusFirst.current = false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
280
283
|
}, [
|
|
281
|
-
manager.collection
|
|
282
|
-
updateActiveDescendant
|
|
284
|
+
manager.collection
|
|
283
285
|
]);
|
|
284
|
-
|
|
286
|
+
// reset focus first flag
|
|
287
|
+
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
285
288
|
// If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't
|
|
286
289
|
// accidentally move focus from under them. Skip this if the collection was empty because we might be in a load
|
|
287
290
|
// state and will still want to focus the first item after load
|
|
288
291
|
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
289
|
-
});
|
|
290
|
-
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
291
|
-
resetFocusFirstFlag();
|
|
292
292
|
}, [
|
|
293
|
-
manager.focusedKey
|
|
294
|
-
resetFocusFirstFlag
|
|
293
|
+
manager.focusedKey
|
|
295
294
|
]);
|
|
296
295
|
(0, $3H3GQ$useEvent)(ref, (0, $3H3GQ$CLEAR_FOCUS_EVENT), !shouldUseVirtualFocus ? undefined : (e)=>{
|
|
297
296
|
var _e_detail;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {getItemElement as $feb5ffebff200149$export$c3d8340acf92597f, isNonContiguousSelectionModifier as $feb5ffebff200149$export$d3e3bd3e26688c04, useCollectionId as $feb5ffebff200149$export$881eb0d9f3605d9d} from "./utils.module.js";
|
|
2
2
|
import {useTypeSelect as $fb3050f43d946246$export$e32c88dfddc6e1d8} from "./useTypeSelect.module.js";
|
|
3
|
-
import {useRouter as $3H3GQ$useRouter, isCtrlKeyPressed as $3H3GQ$isCtrlKeyPressed, focusWithoutScrolling as $3H3GQ$focusWithoutScrolling, useEvent as $3H3GQ$useEvent, scrollIntoViewport as $3H3GQ$scrollIntoViewport, FOCUS_EVENT as $3H3GQ$FOCUS_EVENT,
|
|
3
|
+
import {useRouter as $3H3GQ$useRouter, isCtrlKeyPressed as $3H3GQ$isCtrlKeyPressed, isTabbable as $3H3GQ$isTabbable, focusWithoutScrolling as $3H3GQ$focusWithoutScrolling, useEvent as $3H3GQ$useEvent, scrollIntoViewport as $3H3GQ$scrollIntoViewport, FOCUS_EVENT as $3H3GQ$FOCUS_EVENT, useUpdateLayoutEffect as $3H3GQ$useUpdateLayoutEffect, getActiveElement as $3H3GQ$getActiveElement, CLEAR_FOCUS_EVENT as $3H3GQ$CLEAR_FOCUS_EVENT, scrollIntoView as $3H3GQ$scrollIntoView, mergeProps as $3H3GQ$mergeProps} from "@react-aria/utils";
|
|
4
4
|
import {getFocusableTreeWalker as $3H3GQ$getFocusableTreeWalker, moveVirtualFocus as $3H3GQ$moveVirtualFocus, dispatchVirtualFocus as $3H3GQ$dispatchVirtualFocus} from "@react-aria/focus";
|
|
5
5
|
import {flushSync as $3H3GQ$flushSync} from "react-dom";
|
|
6
6
|
import {useRef as $3H3GQ$useRef, useEffect as $3H3GQ$useEffect} from "react";
|
|
@@ -174,7 +174,10 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
|
|
|
174
174
|
last = walker.lastChild();
|
|
175
175
|
if (last) next = last;
|
|
176
176
|
}while (last);
|
|
177
|
-
|
|
177
|
+
// If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to
|
|
178
|
+
// the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between
|
|
179
|
+
// focusing the containing cell and back to the non-tabbable child element
|
|
180
|
+
if (next && (!next.contains(document.activeElement) || document.activeElement && !(0, $3H3GQ$isTabbable)(document.activeElement))) (0, $3H3GQ$focusWithoutScrolling)(next);
|
|
178
181
|
}
|
|
179
182
|
break;
|
|
180
183
|
}
|
|
@@ -254,44 +257,40 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
|
|
|
254
257
|
// If the user is typing forwards, autofocus the first option in the list.
|
|
255
258
|
if ((detail === null || detail === void 0 ? void 0 : detail.focusStrategy) === 'first') shouldVirtualFocusFirst.current = true;
|
|
256
259
|
});
|
|
257
|
-
|
|
258
|
-
var _delegate_getFirstKey;
|
|
259
|
-
var _delegate_getFirstKey1;
|
|
260
|
-
let keyToFocus = (_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;
|
|
261
|
-
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
262
|
-
// the original active element (e.g. the autocomplete input)
|
|
263
|
-
if (keyToFocus == null) {
|
|
264
|
-
let previousActiveElement = (0, $3H3GQ$getActiveElement)();
|
|
265
|
-
(0, $3H3GQ$moveVirtualFocus)(ref.current);
|
|
266
|
-
(0, $3H3GQ$dispatchVirtualFocus)(previousActiveElement, null);
|
|
267
|
-
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
268
|
-
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
269
|
-
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
270
|
-
} else {
|
|
271
|
-
manager.setFocusedKey(keyToFocus);
|
|
272
|
-
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
273
|
-
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
274
|
-
// after the collection updates after load
|
|
275
|
-
shouldVirtualFocusFirst.current = false;
|
|
276
|
-
}
|
|
277
|
-
});
|
|
260
|
+
// update active descendant
|
|
278
261
|
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
279
|
-
if (shouldVirtualFocusFirst.current)
|
|
262
|
+
if (shouldVirtualFocusFirst.current) {
|
|
263
|
+
var _delegate_getFirstKey;
|
|
264
|
+
var _delegate_getFirstKey1;
|
|
265
|
+
let keyToFocus = (_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;
|
|
266
|
+
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
267
|
+
// the original active element (e.g. the autocomplete input)
|
|
268
|
+
if (keyToFocus == null) {
|
|
269
|
+
let previousActiveElement = (0, $3H3GQ$getActiveElement)();
|
|
270
|
+
(0, $3H3GQ$moveVirtualFocus)(ref.current);
|
|
271
|
+
(0, $3H3GQ$dispatchVirtualFocus)(previousActiveElement, null);
|
|
272
|
+
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
273
|
+
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
274
|
+
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
275
|
+
} else {
|
|
276
|
+
manager.setFocusedKey(keyToFocus);
|
|
277
|
+
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
278
|
+
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
279
|
+
// after the collection updates after load
|
|
280
|
+
shouldVirtualFocusFirst.current = false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
280
283
|
}, [
|
|
281
|
-
manager.collection
|
|
282
|
-
updateActiveDescendant
|
|
284
|
+
manager.collection
|
|
283
285
|
]);
|
|
284
|
-
|
|
286
|
+
// reset focus first flag
|
|
287
|
+
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
285
288
|
// If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't
|
|
286
289
|
// accidentally move focus from under them. Skip this if the collection was empty because we might be in a load
|
|
287
290
|
// state and will still want to focus the first item after load
|
|
288
291
|
if (manager.collection.size > 0) shouldVirtualFocusFirst.current = false;
|
|
289
|
-
});
|
|
290
|
-
(0, $3H3GQ$useUpdateLayoutEffect)(()=>{
|
|
291
|
-
resetFocusFirstFlag();
|
|
292
292
|
}, [
|
|
293
|
-
manager.focusedKey
|
|
294
|
-
resetFocusFirstFlag
|
|
293
|
+
manager.focusedKey
|
|
295
294
|
]);
|
|
296
295
|
(0, $3H3GQ$useEvent)(ref, (0, $3H3GQ$CLEAR_FOCUS_EVENT), !shouldUseVirtualFocus ? undefined : (e)=>{
|
|
297
296
|
var _e_detail;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,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;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\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, getInteractionModality} from '@react-aria/interactions';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} 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 pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\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 escapeKeyBehavior = 'clearSelection',\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 = getItemElement(ref, key);\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 (escapeKeyBehavior === 'clearSelection' && !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 if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\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 navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(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 = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\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) && !shouldUseVirtualFocus) {\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 // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (keyToFocus == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\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 // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\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' || didAutoFocusRef.current) {\n\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\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 }\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 didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oB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,mBACH,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, isTabbable, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\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, getInteractionModality} from '@react-aria/interactions';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} 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 pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\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 escapeKeyBehavior = 'clearSelection',\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 = getItemElement(ref, key);\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\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 (escapeKeyBehavior === 'clearSelection' && !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 the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to\n // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between\n // focusing the containing cell and back to the non-tabbable child element\n if (next && (!next.contains(document.activeElement) || (document.activeElement && !isTabbable(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 if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\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 navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(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 = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\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) && !shouldUseVirtualFocus) {\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 // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n // update active descendant\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n // the original active element (e.g. the autocomplete input)\n if (keyToFocus == null) {\n let previousActiveElement = getActiveElement();\n moveVirtualFocus(ref.current);\n dispatchVirtualFocus(previousActiveElement!, null);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n }\n }, [manager.collection]);\n\n // reset focus first flag\n useUpdateLayoutEffect(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n }, [manager.focusedKey]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\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 // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n let raf = useRef<number | null>(null);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\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' || didAutoFocusRef.current) {\n\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n\n raf.current = requestAnimationFrame(() => {\n if (scrollRef.current) {\n scrollIntoView(scrollRef.current, element);\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 }\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 didAutoFocusRef.current = false;\n });\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\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 let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/selection",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.27.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/focus": "^3.21.
|
|
30
|
-
"@react-aria/i18n": "^3.12.
|
|
31
|
-
"@react-aria/interactions": "^3.
|
|
32
|
-
"@react-aria/utils": "^3.
|
|
33
|
-
"@react-stately/selection": "^3.20.
|
|
29
|
+
"@react-aria/focus": "^3.21.3",
|
|
30
|
+
"@react-aria/i18n": "^3.12.14",
|
|
31
|
+
"@react-aria/interactions": "^3.26.0",
|
|
32
|
+
"@react-aria/utils": "^3.32.0",
|
|
33
|
+
"@react-stately/selection": "^3.20.7",
|
|
34
34
|
"@react-types/shared": "^3.32.1",
|
|
35
35
|
"@swc/helpers": "^0.5.0"
|
|
36
36
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
|
|
45
45
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport,
|
|
13
|
+
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, getActiveElement, isCtrlKeyPressed, isTabbable, mergeProps, scrollIntoView, scrollIntoViewport, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';
|
|
14
14
|
import {dispatchVirtualFocus, getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';
|
|
15
15
|
import {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';
|
|
16
16
|
import {flushSync} from 'react-dom';
|
|
@@ -312,7 +312,10 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
312
312
|
}
|
|
313
313
|
} while (last);
|
|
314
314
|
|
|
315
|
-
|
|
315
|
+
// If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to
|
|
316
|
+
// the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between
|
|
317
|
+
// focusing the containing cell and back to the non-tabbable child element
|
|
318
|
+
if (next && (!next.contains(document.activeElement) || (document.activeElement && !isTabbable(document.activeElement)))) {
|
|
316
319
|
focusWithoutScrolling(next);
|
|
317
320
|
}
|
|
318
321
|
}
|
|
@@ -413,49 +416,42 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
|
|
|
413
416
|
}
|
|
414
417
|
});
|
|
415
418
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
419
|
+
// update active descendant
|
|
420
|
+
useUpdateLayoutEffect(() => {
|
|
421
|
+
if (shouldVirtualFocusFirst.current) {
|
|
422
|
+
let keyToFocus = delegate.getFirstKey?.() ?? null;
|
|
423
|
+
|
|
424
|
+
// If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to
|
|
425
|
+
// the original active element (e.g. the autocomplete input)
|
|
426
|
+
if (keyToFocus == null) {
|
|
427
|
+
let previousActiveElement = getActiveElement();
|
|
428
|
+
moveVirtualFocus(ref.current);
|
|
429
|
+
dispatchVirtualFocus(previousActiveElement!, null);
|
|
430
|
+
|
|
431
|
+
// If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.
|
|
432
|
+
// Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.
|
|
433
|
+
if (manager.collection.size > 0) {
|
|
434
|
+
shouldVirtualFocusFirst.current = false;
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
manager.setFocusedKey(keyToFocus);
|
|
438
|
+
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
439
|
+
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
440
|
+
// after the collection updates after load
|
|
429
441
|
shouldVirtualFocusFirst.current = false;
|
|
430
442
|
}
|
|
431
|
-
} else {
|
|
432
|
-
manager.setFocusedKey(keyToFocus);
|
|
433
|
-
// Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key
|
|
434
|
-
// If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key
|
|
435
|
-
// after the collection updates after load
|
|
436
|
-
shouldVirtualFocusFirst.current = false;
|
|
437
443
|
}
|
|
438
|
-
});
|
|
444
|
+
}, [manager.collection]);
|
|
439
445
|
|
|
446
|
+
// reset focus first flag
|
|
440
447
|
useUpdateLayoutEffect(() => {
|
|
441
|
-
if (shouldVirtualFocusFirst.current) {
|
|
442
|
-
updateActiveDescendant();
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
}, [manager.collection, updateActiveDescendant]);
|
|
446
|
-
|
|
447
|
-
let resetFocusFirstFlag = useEffectEvent(() => {
|
|
448
448
|
// If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't
|
|
449
449
|
// accidentally move focus from under them. Skip this if the collection was empty because we might be in a load
|
|
450
450
|
// state and will still want to focus the first item after load
|
|
451
451
|
if (manager.collection.size > 0) {
|
|
452
452
|
shouldVirtualFocusFirst.current = false;
|
|
453
453
|
}
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
useUpdateLayoutEffect(() => {
|
|
457
|
-
resetFocusFirstFlag();
|
|
458
|
-
}, [manager.focusedKey, resetFocusFirstFlag]);
|
|
454
|
+
}, [manager.focusedKey]);
|
|
459
455
|
|
|
460
456
|
useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {
|
|
461
457
|
e.stopPropagation();
|