@react-aria/grid 3.14.8 → 3.15.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/import.mjs +9 -9
- package/dist/main.js +16 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +9 -9
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +16 -0
- package/package.json +15 -23
- package/src/index.ts +16 -16
- package/dist/GridKeyboardDelegate.main.js +0 -318
- package/dist/GridKeyboardDelegate.main.js.map +0 -1
- package/dist/GridKeyboardDelegate.mjs +0 -313
- package/dist/GridKeyboardDelegate.module.js +0 -313
- package/dist/GridKeyboardDelegate.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -15
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -17
- package/dist/ar-AE.module.js +0 -17
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -15
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -17
- package/dist/bg-BG.module.js +0 -17
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -15
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -17
- package/dist/cs-CZ.module.js +0 -17
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -15
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -17
- package/dist/da-DK.module.js +0 -17
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -15
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -17
- package/dist/de-DE.module.js +0 -17
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -15
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -17
- package/dist/el-GR.module.js +0 -17
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -15
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -17
- package/dist/en-US.module.js +0 -17
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -15
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -17
- package/dist/es-ES.module.js +0 -17
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -15
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -17
- package/dist/et-EE.module.js +0 -17
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -15
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -17
- package/dist/fi-FI.module.js +0 -17
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -15
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -17
- package/dist/fr-FR.module.js +0 -17
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -15
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -17
- package/dist/he-IL.module.js +0 -17
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -15
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -17
- package/dist/hr-HR.module.js +0 -17
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -15
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -17
- package/dist/hu-HU.module.js +0 -17
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -15
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -17
- package/dist/it-IT.module.js +0 -17
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -15
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -17
- package/dist/ja-JP.module.js +0 -17
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -15
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -17
- package/dist/ko-KR.module.js +0 -17
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -15
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -17
- package/dist/lt-LT.module.js +0 -17
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -15
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -17
- package/dist/lv-LV.module.js +0 -17
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -15
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -17
- package/dist/nb-NO.module.js +0 -17
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -15
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -17
- package/dist/nl-NL.module.js +0 -17
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -15
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -17
- package/dist/pl-PL.module.js +0 -17
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -15
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -17
- package/dist/pt-BR.module.js +0 -17
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -15
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -17
- package/dist/pt-PT.module.js +0 -17
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -15
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -17
- package/dist/ro-RO.module.js +0 -17
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -15
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -17
- package/dist/ru-RU.module.js +0 -17
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -15
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -17
- package/dist/sk-SK.module.js +0 -17
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -15
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -17
- package/dist/sl-SI.module.js +0 -17
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -15
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -17
- package/dist/sr-SP.module.js +0 -17
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -15
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -17
- package/dist/sv-SE.module.js +0 -17
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -15
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -17
- package/dist/tr-TR.module.js +0 -17
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -213
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -15
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -17
- package/dist/uk-UA.module.js +0 -17
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useGrid.main.js +0 -135
- package/dist/useGrid.main.js.map +0 -1
- package/dist/useGrid.mjs +0 -130
- package/dist/useGrid.module.js +0 -130
- package/dist/useGrid.module.js.map +0 -1
- package/dist/useGridCell.main.js +0 -231
- package/dist/useGridCell.main.js.map +0 -1
- package/dist/useGridCell.mjs +0 -226
- package/dist/useGridCell.module.js +0 -226
- package/dist/useGridCell.module.js.map +0 -1
- package/dist/useGridRow.main.js +0 -56
- package/dist/useGridRow.main.js.map +0 -1
- package/dist/useGridRow.mjs +0 -51
- package/dist/useGridRow.module.js +0 -51
- package/dist/useGridRow.module.js.map +0 -1
- package/dist/useGridRowGroup.main.js +0 -26
- package/dist/useGridRowGroup.main.js.map +0 -1
- package/dist/useGridRowGroup.mjs +0 -21
- package/dist/useGridRowGroup.module.js +0 -21
- package/dist/useGridRowGroup.module.js.map +0 -1
- package/dist/useGridSelectionAnnouncement.main.js +0 -118
- package/dist/useGridSelectionAnnouncement.main.js.map +0 -1
- package/dist/useGridSelectionAnnouncement.mjs +0 -113
- package/dist/useGridSelectionAnnouncement.module.js +0 -113
- package/dist/useGridSelectionAnnouncement.module.js.map +0 -1
- package/dist/useGridSelectionCheckbox.main.js +0 -39
- package/dist/useGridSelectionCheckbox.main.js.map +0 -1
- package/dist/useGridSelectionCheckbox.mjs +0 -34
- package/dist/useGridSelectionCheckbox.module.js +0 -34
- package/dist/useGridSelectionCheckbox.module.js.map +0 -1
- package/dist/useHighlightSelectionDescription.main.js +0 -55
- package/dist/useHighlightSelectionDescription.main.js.map +0 -1
- package/dist/useHighlightSelectionDescription.mjs +0 -50
- package/dist/useHighlightSelectionDescription.module.js +0 -50
- package/dist/useHighlightSelectionDescription.module.js.map +0 -1
- package/dist/utils.main.js +0 -20
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -15
- package/dist/utils.module.js +0 -15
- package/dist/utils.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -15
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -17
- package/dist/zh-CN.module.js +0 -17
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -15
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -17
- package/dist/zh-TW.module.js +0 -17
- package/dist/zh-TW.module.js.map +0 -1
- package/src/GridKeyboardDelegate.ts +0 -484
- package/src/useGrid.ts +0 -186
- package/src/useGridCell.ts +0 -300
- package/src/useGridRow.ts +0 -84
- package/src/useGridRowGroup.ts +0 -29
- package/src/useGridSelectionAnnouncement.ts +0 -140
- package/src/useGridSelectionCheckbox.ts +0 -48
- package/src/useHighlightSelectionDescription.ts +0 -52
- package/src/utils.ts +0 -29
package/src/useGridCell.ts
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';
|
|
14
|
-
import {focusSafely, isFocusVisible} from '@react-aria/interactions';
|
|
15
|
-
import {getActiveElement, getEventTarget, getScrollParent, isFocusWithin, mergeProps, nodeContains, scrollIntoViewport} from '@react-aria/utils';
|
|
16
|
-
import {getFocusableTreeWalker} from '@react-aria/focus';
|
|
17
|
-
import {GridCollection, GridNode} from '@react-types/grid';
|
|
18
|
-
import {gridMap} from './utils';
|
|
19
|
-
import {GridState} from '@react-stately/grid';
|
|
20
|
-
import {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';
|
|
21
|
-
import {useLocale} from '@react-aria/i18n';
|
|
22
|
-
import {useSelectableItem} from '@react-aria/selection';
|
|
23
|
-
|
|
24
|
-
export interface GridCellProps {
|
|
25
|
-
/** An object representing the grid cell. Contains all the relevant information that makes up the grid cell. */
|
|
26
|
-
node: GridNode<unknown>,
|
|
27
|
-
/** Whether the grid cell is contained in a virtual scroller. */
|
|
28
|
-
isVirtualized?: boolean,
|
|
29
|
-
/** Whether the cell or its first focusable child element should be focused when the grid cell is focused. */
|
|
30
|
-
focusMode?: 'child' | 'cell',
|
|
31
|
-
/** Whether selection should occur on press up instead of press down. */
|
|
32
|
-
shouldSelectOnPressUp?: boolean,
|
|
33
|
-
/** Indicates how many columns the data cell spans. */
|
|
34
|
-
colSpan?: number,
|
|
35
|
-
/**
|
|
36
|
-
* Handler that is called when a user performs an action on the cell.
|
|
37
|
-
* Please use onCellAction at the collection level instead.
|
|
38
|
-
* @deprecated
|
|
39
|
-
**/
|
|
40
|
-
onAction?: () => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface GridCellAria {
|
|
44
|
-
/** Props for the grid cell element. */
|
|
45
|
-
gridCellProps: DOMAttributes,
|
|
46
|
-
/** Whether the cell is currently in a pressed state. */
|
|
47
|
-
isPressed: boolean
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Provides the behavior and accessibility implementation for a cell in a grid.
|
|
52
|
-
* @param props - Props for the cell.
|
|
53
|
-
* @param state - State of the parent grid, as returned by `useGridState`.
|
|
54
|
-
*/
|
|
55
|
-
export function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps, state: GridState<T, C>, ref: RefObject<FocusableElement | null>): GridCellAria {
|
|
56
|
-
let {
|
|
57
|
-
node,
|
|
58
|
-
isVirtualized,
|
|
59
|
-
focusMode = 'child',
|
|
60
|
-
shouldSelectOnPressUp,
|
|
61
|
-
onAction
|
|
62
|
-
} = props;
|
|
63
|
-
|
|
64
|
-
let {direction} = useLocale();
|
|
65
|
-
let {keyboardDelegate, actions: {onCellAction}} = gridMap.get(state)!;
|
|
66
|
-
|
|
67
|
-
// We need to track the key of the item at the time it was last focused so that we force
|
|
68
|
-
// focus to go to the item when the DOM node is reused for a different item in a virtualizer.
|
|
69
|
-
let keyWhenFocused = useRef<Key | null>(null);
|
|
70
|
-
|
|
71
|
-
// Handles focusing the cell. If there is a focusable child,
|
|
72
|
-
// it is focused, otherwise the cell itself is focused.
|
|
73
|
-
let focus = () => {
|
|
74
|
-
if (ref.current) {
|
|
75
|
-
let treeWalker = getFocusableTreeWalker(ref.current);
|
|
76
|
-
if (focusMode === 'child') {
|
|
77
|
-
// If focus is already on a focusable child within the cell, early return so we don't shift focus
|
|
78
|
-
if (isFocusWithin(ref.current) && ref.current !== getActiveElement()) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let focusable = state.selectionManager.childFocusStrategy === 'last'
|
|
83
|
-
? last(treeWalker)
|
|
84
|
-
: treeWalker.firstChild() as FocusableElement;
|
|
85
|
-
if (focusable) {
|
|
86
|
-
focusSafely(focusable);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
(keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||
|
|
93
|
-
!isFocusWithin(ref.current)
|
|
94
|
-
) {
|
|
95
|
-
focusSafely(ref.current);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
let {itemProps, isPressed} = useSelectableItem({
|
|
101
|
-
selectionManager: state.selectionManager,
|
|
102
|
-
key: node.key,
|
|
103
|
-
ref,
|
|
104
|
-
isVirtualized,
|
|
105
|
-
focus,
|
|
106
|
-
shouldSelectOnPressUp,
|
|
107
|
-
onAction: onCellAction ? () => onCellAction(node.key) : onAction,
|
|
108
|
-
isDisabled: state.collection.size === 0
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
let onKeyDownCapture = (e: ReactKeyboardEvent) => {
|
|
112
|
-
let activeElement = getActiveElement();
|
|
113
|
-
if (!nodeContains(e.currentTarget, getEventTarget(e) as Element) || state.isKeyboardNavigationDisabled || !ref.current || !activeElement) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let walker = getFocusableTreeWalker(ref.current);
|
|
118
|
-
walker.currentNode = activeElement;
|
|
119
|
-
|
|
120
|
-
switch (e.key) {
|
|
121
|
-
case 'ArrowLeft': {
|
|
122
|
-
// Find the next focusable element within the cell.
|
|
123
|
-
let focusable: FocusableElement | null = direction === 'rtl'
|
|
124
|
-
? walker.nextNode() as FocusableElement
|
|
125
|
-
: walker.previousNode() as FocusableElement;
|
|
126
|
-
|
|
127
|
-
// Don't focus the cell itself if focusMode is "child"
|
|
128
|
-
if (focusMode === 'child' && focusable === ref.current) {
|
|
129
|
-
focusable = null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
e.stopPropagation();
|
|
134
|
-
if (focusable) {
|
|
135
|
-
focusSafely(focusable);
|
|
136
|
-
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
137
|
-
} else {
|
|
138
|
-
// If there is no next focusable child, then move to the next cell to the left of this one.
|
|
139
|
-
// This will be handled by useSelectableCollection. However, if there is no cell to the left
|
|
140
|
-
// of this one, only one column, and the grid doesn't focus rows, then the next key will be the
|
|
141
|
-
// same as this one. In that case we need to handle focusing either the cell or the first/last
|
|
142
|
-
// child, depending on the focus mode.
|
|
143
|
-
let prev = keyboardDelegate.getKeyLeftOf?.(node.key);
|
|
144
|
-
if (prev !== node.key) {
|
|
145
|
-
// We prevent the capturing event from reaching children of the cell, e.g. pickers.
|
|
146
|
-
// We want arrow keys to navigate to the next cell instead. We need to re-dispatch
|
|
147
|
-
// the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.
|
|
148
|
-
ref.current.parentElement?.dispatchEvent(
|
|
149
|
-
new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
|
|
150
|
-
);
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (focusMode === 'cell' && direction === 'rtl') {
|
|
155
|
-
focusSafely(ref.current);
|
|
156
|
-
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
157
|
-
} else {
|
|
158
|
-
walker.currentNode = ref.current;
|
|
159
|
-
focusable = direction === 'rtl'
|
|
160
|
-
? walker.firstChild() as FocusableElement
|
|
161
|
-
: last(walker);
|
|
162
|
-
if (focusable) {
|
|
163
|
-
focusSafely(focusable);
|
|
164
|
-
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
case 'ArrowRight': {
|
|
171
|
-
let focusable: FocusableElement | null = direction === 'rtl'
|
|
172
|
-
? walker.previousNode() as FocusableElement
|
|
173
|
-
: walker.nextNode() as FocusableElement;
|
|
174
|
-
|
|
175
|
-
if (focusMode === 'child' && focusable === ref.current) {
|
|
176
|
-
focusable = null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
e.preventDefault();
|
|
180
|
-
e.stopPropagation();
|
|
181
|
-
if (focusable) {
|
|
182
|
-
focusSafely(focusable);
|
|
183
|
-
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
184
|
-
} else {
|
|
185
|
-
let next = keyboardDelegate.getKeyRightOf?.(node.key);
|
|
186
|
-
if (next !== node.key) {
|
|
187
|
-
// We prevent the capturing event from reaching children of the cell, e.g. pickers.
|
|
188
|
-
// We want arrow keys to navigate to the next cell instead. We need to re-dispatch
|
|
189
|
-
// the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.
|
|
190
|
-
ref.current.parentElement?.dispatchEvent(
|
|
191
|
-
new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
|
|
192
|
-
);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (focusMode === 'cell' && direction === 'ltr') {
|
|
197
|
-
focusSafely(ref.current);
|
|
198
|
-
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
199
|
-
} else {
|
|
200
|
-
walker.currentNode = ref.current;
|
|
201
|
-
focusable = direction === 'rtl'
|
|
202
|
-
? last(walker)
|
|
203
|
-
: walker.firstChild() as FocusableElement;
|
|
204
|
-
if (focusable) {
|
|
205
|
-
focusSafely(focusable);
|
|
206
|
-
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
case 'ArrowUp':
|
|
213
|
-
case 'ArrowDown':
|
|
214
|
-
// Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate
|
|
215
|
-
// to the cell above/below instead. We need to re-dispatch the event from a higher parent so it still
|
|
216
|
-
// bubbles and gets handled by useSelectableCollection.
|
|
217
|
-
if (!e.altKey && nodeContains(ref.current, getEventTarget(e) as Element)) {
|
|
218
|
-
e.stopPropagation();
|
|
219
|
-
e.preventDefault();
|
|
220
|
-
ref.current.parentElement?.dispatchEvent(
|
|
221
|
-
new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// Grid cells can have focusable elements inside them. In this case, focus should
|
|
229
|
-
// be marshalled to that element rather than focusing the cell itself.
|
|
230
|
-
let onFocus = (e) => {
|
|
231
|
-
keyWhenFocused.current = node.key;
|
|
232
|
-
if (getEventTarget(e) !== ref.current) {
|
|
233
|
-
// useSelectableItem only handles setting the focused key when
|
|
234
|
-
// the focused element is the gridcell itself. We also want to
|
|
235
|
-
// set the focused key when a child element receives focus.
|
|
236
|
-
// If focus is currently visible (e.g. the user is navigating with the keyboard),
|
|
237
|
-
// then skip this. We want to restore focus to the previously focused row/cell
|
|
238
|
-
// in that case since the table should act like a single tab stop.
|
|
239
|
-
if (!isFocusVisible()) {
|
|
240
|
-
state.selectionManager.setFocusedKey(node.key);
|
|
241
|
-
}
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// If the cell itself is focused, wait a frame so that focus finishes propagatating
|
|
246
|
-
// up to the tree, and move focus to a focusable child if possible.
|
|
247
|
-
requestAnimationFrame(() => {
|
|
248
|
-
if (focusMode === 'child' && getActiveElement() === ref.current) {
|
|
249
|
-
focus();
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
let gridCellProps: DOMAttributes = mergeProps(itemProps, {
|
|
255
|
-
role: 'gridcell',
|
|
256
|
-
onKeyDownCapture,
|
|
257
|
-
'aria-colspan': node.colSpan,
|
|
258
|
-
'aria-colindex': node.colIndex != null ? node.colIndex + 1 : undefined, // aria-colindex is 1-based
|
|
259
|
-
colSpan: isVirtualized ? undefined : node.colSpan,
|
|
260
|
-
onFocus
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
if (isVirtualized) {
|
|
264
|
-
gridCellProps['aria-colindex'] = (node.colIndex ?? node.index) + 1; // aria-colindex is 1-based
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// When pressing with a pointer and cell selection is not enabled, usePress will be applied to the
|
|
268
|
-
// row rather than the cell. However, when the row is draggable, usePress cannot preventDefault
|
|
269
|
-
// on pointer down, so the browser will try to focus the cell which has a tabIndex applied.
|
|
270
|
-
// To avoid this, remove the tabIndex from the cell briefly on pointer down.
|
|
271
|
-
if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) {
|
|
272
|
-
gridCellProps.onPointerDown = (e) => {
|
|
273
|
-
let el = e.currentTarget;
|
|
274
|
-
let tabindex = el.getAttribute('tabindex');
|
|
275
|
-
el.removeAttribute('tabindex');
|
|
276
|
-
requestAnimationFrame(() => {
|
|
277
|
-
if (tabindex != null) {
|
|
278
|
-
el.setAttribute('tabindex', tabindex);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
gridCellProps,
|
|
286
|
-
isPressed
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function last(walker: TreeWalker) {
|
|
291
|
-
let next: FocusableElement | null = null;
|
|
292
|
-
let last: FocusableElement | null = null;
|
|
293
|
-
do {
|
|
294
|
-
last = walker.lastChild() as FocusableElement | null;
|
|
295
|
-
if (last) {
|
|
296
|
-
next = last;
|
|
297
|
-
}
|
|
298
|
-
} while (last);
|
|
299
|
-
return next;
|
|
300
|
-
}
|
package/src/useGridRow.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {chain} from '@react-aria/utils';
|
|
14
|
-
import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
|
|
15
|
-
import {GridCollection, GridNode} from '@react-types/grid';
|
|
16
|
-
import {gridMap} from './utils';
|
|
17
|
-
import {GridState} from '@react-stately/grid';
|
|
18
|
-
import {SelectableItemStates, useSelectableItem} from '@react-aria/selection';
|
|
19
|
-
|
|
20
|
-
export interface GridRowProps<T> {
|
|
21
|
-
/** An object representing the grid row. Contains all the relevant information that makes up the grid row. */
|
|
22
|
-
node: GridNode<T>,
|
|
23
|
-
/** Whether the grid row is contained in a virtual scroller. */
|
|
24
|
-
isVirtualized?: boolean,
|
|
25
|
-
/** Whether selection should occur on press up instead of press down. */
|
|
26
|
-
shouldSelectOnPressUp?: boolean,
|
|
27
|
-
/**
|
|
28
|
-
* Handler that is called when a user performs an action on the row.
|
|
29
|
-
* Please use onCellAction at the collection level instead.
|
|
30
|
-
* @deprecated
|
|
31
|
-
**/
|
|
32
|
-
onAction?: () => void
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface GridRowAria extends SelectableItemStates {
|
|
36
|
-
/** Props for the grid row element. */
|
|
37
|
-
rowProps: DOMAttributes,
|
|
38
|
-
/** Whether the row is currently in a pressed state. */
|
|
39
|
-
isPressed: boolean
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Provides the behavior and accessibility implementation for a row in a grid.
|
|
44
|
-
* @param props - Props for the row.
|
|
45
|
-
* @param state - State of the parent grid, as returned by `useGridState`.
|
|
46
|
-
*/
|
|
47
|
-
export function useGridRow<T, C extends GridCollection<T>, S extends GridState<T, C>>(props: GridRowProps<T>, state: S, ref: RefObject<FocusableElement | null>): GridRowAria {
|
|
48
|
-
let {
|
|
49
|
-
node,
|
|
50
|
-
isVirtualized,
|
|
51
|
-
shouldSelectOnPressUp,
|
|
52
|
-
onAction
|
|
53
|
-
} = props;
|
|
54
|
-
|
|
55
|
-
let {actions, shouldSelectOnPressUp: gridShouldSelectOnPressUp} = gridMap.get(state)!;
|
|
56
|
-
let onRowAction = actions.onRowAction ? () => actions.onRowAction?.(node.key) : onAction;
|
|
57
|
-
let {itemProps, ...states} = useSelectableItem({
|
|
58
|
-
selectionManager: state.selectionManager,
|
|
59
|
-
key: node.key,
|
|
60
|
-
ref,
|
|
61
|
-
isVirtualized,
|
|
62
|
-
shouldSelectOnPressUp: gridShouldSelectOnPressUp || shouldSelectOnPressUp,
|
|
63
|
-
onAction: onRowAction || node?.props?.onAction ? chain(node?.props?.onAction, onRowAction) : undefined,
|
|
64
|
-
isDisabled: state.collection.size === 0
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
let isSelected = state.selectionManager.isSelected(node.key);
|
|
68
|
-
|
|
69
|
-
let rowProps: DOMAttributes = {
|
|
70
|
-
role: 'row',
|
|
71
|
-
'aria-selected': state.selectionManager.selectionMode !== 'none' ? isSelected : undefined,
|
|
72
|
-
'aria-disabled': states.isDisabled || undefined,
|
|
73
|
-
...itemProps
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
if (isVirtualized) {
|
|
77
|
-
rowProps['aria-rowindex'] = node.index + 1; // aria-rowindex is 1 based
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
rowProps,
|
|
82
|
-
...states
|
|
83
|
-
};
|
|
84
|
-
}
|
package/src/useGridRowGroup.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {DOMAttributes} from '@react-types/shared';
|
|
14
|
-
|
|
15
|
-
export interface GridRowGroupAria {
|
|
16
|
-
/** Props for the row group element. */
|
|
17
|
-
rowGroupProps: DOMAttributes
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Provides the accessibility implementation for a row group in a grid.
|
|
22
|
-
*/
|
|
23
|
-
export function useGridRowGroup(): GridRowGroupAria {
|
|
24
|
-
return {
|
|
25
|
-
rowGroupProps: {
|
|
26
|
-
role: 'rowgroup'
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {announce} from '@react-aria/live-announcer';
|
|
14
|
-
import {Collection, Key, Node, Selection} from '@react-types/shared';
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
import intlMessages from '../intl/*.json';
|
|
17
|
-
import {SelectionManager} from '@react-stately/selection';
|
|
18
|
-
import {useCallback, useRef} from 'react';
|
|
19
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
20
|
-
import {useUpdateEffect} from '@react-aria/utils';
|
|
21
|
-
|
|
22
|
-
export interface GridSelectionAnnouncementProps {
|
|
23
|
-
/**
|
|
24
|
-
* A function that returns the text that should be announced by assistive technology when a row is added or removed from selection.
|
|
25
|
-
* @default (key) => state.collection.getItem(key)?.textValue
|
|
26
|
-
*/
|
|
27
|
-
getRowText?: (key: Key) => string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface GridSelectionState<T> {
|
|
31
|
-
/** A collection of items in the grid. */
|
|
32
|
-
collection: Collection<Node<T>>,
|
|
33
|
-
/** A set of items that are disabled. */
|
|
34
|
-
disabledKeys: Set<Key>,
|
|
35
|
-
/** A selection manager to read and update multiple selection state. */
|
|
36
|
-
selectionManager: SelectionManager
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function useGridSelectionAnnouncement<T>(props: GridSelectionAnnouncementProps, state: GridSelectionState<T>): void {
|
|
40
|
-
let {
|
|
41
|
-
getRowText = (key) => state.collection.getTextValue?.(key) ?? state.collection.getItem(key)?.textValue
|
|
42
|
-
} = props;
|
|
43
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid');
|
|
44
|
-
|
|
45
|
-
// Many screen readers do not announce when items in a grid are selected/deselected.
|
|
46
|
-
// We do this using an ARIA live region.
|
|
47
|
-
let selection = state.selectionManager.rawSelection;
|
|
48
|
-
let lastSelection = useRef(selection);
|
|
49
|
-
let announceSelectionChange = useCallback(() => {
|
|
50
|
-
if (!state.selectionManager.isFocused || selection === lastSelection.current) {
|
|
51
|
-
lastSelection.current = selection;
|
|
52
|
-
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let addedKeys = diffSelection(selection, lastSelection.current);
|
|
57
|
-
let removedKeys = diffSelection(lastSelection.current, selection);
|
|
58
|
-
|
|
59
|
-
// If adding or removing a single row from the selection, announce the name of that item.
|
|
60
|
-
let isReplace = state.selectionManager.selectionBehavior === 'replace';
|
|
61
|
-
let messages: string[] = [];
|
|
62
|
-
|
|
63
|
-
if ((state.selectionManager.selectedKeys.size === 1 && isReplace)) {
|
|
64
|
-
let firstKey = state.selectionManager.selectedKeys.keys().next().value;
|
|
65
|
-
if (firstKey != null && state.collection.getItem(firstKey)) {
|
|
66
|
-
let currentSelectionText = getRowText(firstKey);
|
|
67
|
-
if (currentSelectionText) {
|
|
68
|
-
messages.push(stringFormatter.format('selectedItem', {item: currentSelectionText}));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else if (addedKeys.size === 1 && removedKeys.size === 0) {
|
|
72
|
-
let firstKey = addedKeys.keys().next().value;
|
|
73
|
-
if (firstKey != null) {
|
|
74
|
-
let addedText = getRowText(firstKey);
|
|
75
|
-
if (addedText) {
|
|
76
|
-
messages.push(stringFormatter.format('selectedItem', {item: addedText}));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} else if (removedKeys.size === 1 && addedKeys.size === 0) {
|
|
80
|
-
let firstKey = removedKeys.keys().next().value;
|
|
81
|
-
if (firstKey != null && state.collection.getItem(firstKey)) {
|
|
82
|
-
let removedText = getRowText(firstKey);
|
|
83
|
-
if (removedText) {
|
|
84
|
-
messages.push(stringFormatter.format('deselectedItem', {item: removedText}));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Announce how many items are selected, except when selecting the first item.
|
|
90
|
-
if (state.selectionManager.selectionMode === 'multiple') {
|
|
91
|
-
if (messages.length === 0 || selection === 'all' || selection.size > 1 || lastSelection.current === 'all' || lastSelection.current?.size > 1) {
|
|
92
|
-
messages.push(selection === 'all'
|
|
93
|
-
? stringFormatter.format('selectedAll')
|
|
94
|
-
: stringFormatter.format('selectedCount', {count: selection.size})
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (messages.length > 0) {
|
|
100
|
-
announce(messages.join(' '));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
lastSelection.current = selection;
|
|
104
|
-
}, [
|
|
105
|
-
selection,
|
|
106
|
-
state.selectionManager.selectedKeys,
|
|
107
|
-
state.selectionManager.isFocused,
|
|
108
|
-
state.selectionManager.selectionBehavior,
|
|
109
|
-
state.selectionManager.selectionMode,
|
|
110
|
-
state.collection,
|
|
111
|
-
getRowText,
|
|
112
|
-
stringFormatter
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
// useUpdateEffect will handle using useEffectEvent, no need to stabilize anything on this end
|
|
116
|
-
useUpdateEffect(() => {
|
|
117
|
-
if (state.selectionManager.isFocused) {
|
|
118
|
-
announceSelectionChange();
|
|
119
|
-
} else {
|
|
120
|
-
// Wait a frame in case the collection is about to become focused (e.g. on mouse down).
|
|
121
|
-
let raf = requestAnimationFrame(announceSelectionChange);
|
|
122
|
-
return () => cancelAnimationFrame(raf);
|
|
123
|
-
}
|
|
124
|
-
}, [selection, state.selectionManager.isFocused]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function diffSelection(a: Selection, b: Selection): Set<Key> {
|
|
128
|
-
let res = new Set<Key>();
|
|
129
|
-
if (a === 'all' || b === 'all') {
|
|
130
|
-
return res;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
for (let key of a.keys()) {
|
|
134
|
-
if (!b.has(key)) {
|
|
135
|
-
res.add(key);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return res;
|
|
140
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {AriaCheckboxProps} from '@react-types/checkbox';
|
|
2
|
-
import {GridCollection} from '@react-types/grid';
|
|
3
|
-
import {GridState} from '@react-stately/grid';
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import intlMessages from '../intl/*.json';
|
|
6
|
-
import {Key} from '@react-types/shared';
|
|
7
|
-
import {useId} from '@react-aria/utils';
|
|
8
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
9
|
-
|
|
10
|
-
export interface AriaGridSelectionCheckboxProps {
|
|
11
|
-
/** A unique key for the checkbox. */
|
|
12
|
-
key: Key
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface GridSelectionCheckboxAria {
|
|
16
|
-
/** Props for the row selection checkbox element. */
|
|
17
|
-
checkboxProps: AriaCheckboxProps
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Provides the behavior and accessibility implementation for a selection checkbox in a grid.
|
|
23
|
-
* @param props - Props for the selection checkbox.
|
|
24
|
-
* @param state - State of the grid, as returned by `useGridState`.
|
|
25
|
-
*/
|
|
26
|
-
export function useGridSelectionCheckbox<T, C extends GridCollection<T>>(props: AriaGridSelectionCheckboxProps, state: GridState<T, C>): GridSelectionCheckboxAria {
|
|
27
|
-
let {key} = props;
|
|
28
|
-
|
|
29
|
-
let manager = state.selectionManager;
|
|
30
|
-
let checkboxId = useId();
|
|
31
|
-
let isDisabled = !state.selectionManager.canSelectItem(key);
|
|
32
|
-
let isSelected = state.selectionManager.isSelected(key);
|
|
33
|
-
|
|
34
|
-
// Checkbox should always toggle selection, regardless of selectionBehavior.
|
|
35
|
-
let onChange = () => manager.toggleSelection(key);
|
|
36
|
-
|
|
37
|
-
const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid');
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
checkboxProps: {
|
|
41
|
-
id: checkboxId,
|
|
42
|
-
'aria-label': stringFormatter.format('select'),
|
|
43
|
-
isSelected,
|
|
44
|
-
isDisabled,
|
|
45
|
-
onChange
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaLabelingProps} from '@react-types/shared';
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
import intlMessages from '../intl/*.json';
|
|
16
|
-
import {MultipleSelectionManager} from '@react-stately/selection';
|
|
17
|
-
import {useDescription} from '@react-aria/utils';
|
|
18
|
-
import {useInteractionModality} from '@react-aria/interactions';
|
|
19
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
20
|
-
import {useMemo} from 'react';
|
|
21
|
-
|
|
22
|
-
export interface HighlightSelectionDescriptionProps {
|
|
23
|
-
selectionManager: MultipleSelectionManager,
|
|
24
|
-
hasItemActions?: boolean
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Computes the description for a grid selectable collection.
|
|
29
|
-
* @param props
|
|
30
|
-
*/
|
|
31
|
-
export function useHighlightSelectionDescription(props: HighlightSelectionDescriptionProps): AriaLabelingProps {
|
|
32
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid');
|
|
33
|
-
let modality = useInteractionModality();
|
|
34
|
-
// null is the default if the user hasn't interacted with the table at all yet or the rest of the page
|
|
35
|
-
let shouldLongPress = (modality === 'pointer' || modality === 'virtual' || modality == null)
|
|
36
|
-
&& typeof window !== 'undefined' && 'ontouchstart' in window;
|
|
37
|
-
|
|
38
|
-
let interactionDescription = useMemo(() => {
|
|
39
|
-
let selectionMode = props.selectionManager.selectionMode;
|
|
40
|
-
let selectionBehavior = props.selectionManager.selectionBehavior;
|
|
41
|
-
|
|
42
|
-
let message: string | undefined;
|
|
43
|
-
if (shouldLongPress) {
|
|
44
|
-
message = stringFormatter.format('longPressToSelect');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return selectionBehavior === 'replace' && selectionMode !== 'none' && props.hasItemActions ? message : undefined;
|
|
48
|
-
}, [props.selectionManager.selectionMode, props.selectionManager.selectionBehavior, props.hasItemActions, stringFormatter, shouldLongPress]);
|
|
49
|
-
|
|
50
|
-
let descriptionProps = useDescription(interactionDescription);
|
|
51
|
-
return descriptionProps;
|
|
52
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type {GridCollection} from '@react-types/grid';
|
|
14
|
-
import type {GridState} from '@react-stately/grid';
|
|
15
|
-
import type {Key, KeyboardDelegate} from '@react-types/shared';
|
|
16
|
-
|
|
17
|
-
interface GridMapShared {
|
|
18
|
-
keyboardDelegate: KeyboardDelegate,
|
|
19
|
-
actions: {
|
|
20
|
-
onRowAction?: (key: Key) => void,
|
|
21
|
-
onCellAction?: (key: Key) => void
|
|
22
|
-
},
|
|
23
|
-
shouldSelectOnPressUp?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Used to share:
|
|
27
|
-
// keyboard delegate between useGrid and useGridCell
|
|
28
|
-
// onRowAction/onCellAction across hooks
|
|
29
|
-
export const gridMap: WeakMap<GridState<unknown, GridCollection<unknown>>, GridMapShared> = new WeakMap<GridState<unknown, GridCollection<unknown>>, GridMapShared>();
|