@react-aria/table 3.17.10 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/dist/import.mjs +2 -19
  2. package/dist/main.js +10 -27
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +2 -19
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +4 -0
  7. package/package.json +15 -25
  8. package/src/index.ts +4 -21
  9. package/dist/TableKeyboardDelegate.main.js +0 -142
  10. package/dist/TableKeyboardDelegate.main.js.map +0 -1
  11. package/dist/TableKeyboardDelegate.mjs +0 -137
  12. package/dist/TableKeyboardDelegate.module.js +0 -137
  13. package/dist/TableKeyboardDelegate.module.js.map +0 -1
  14. package/dist/ar-AE.main.js +0 -14
  15. package/dist/ar-AE.main.js.map +0 -1
  16. package/dist/ar-AE.mjs +0 -16
  17. package/dist/ar-AE.module.js +0 -16
  18. package/dist/ar-AE.module.js.map +0 -1
  19. package/dist/bg-BG.main.js +0 -14
  20. package/dist/bg-BG.main.js.map +0 -1
  21. package/dist/bg-BG.mjs +0 -16
  22. package/dist/bg-BG.module.js +0 -16
  23. package/dist/bg-BG.module.js.map +0 -1
  24. package/dist/cs-CZ.main.js +0 -14
  25. package/dist/cs-CZ.main.js.map +0 -1
  26. package/dist/cs-CZ.mjs +0 -16
  27. package/dist/cs-CZ.module.js +0 -16
  28. package/dist/cs-CZ.module.js.map +0 -1
  29. package/dist/da-DK.main.js +0 -14
  30. package/dist/da-DK.main.js.map +0 -1
  31. package/dist/da-DK.mjs +0 -16
  32. package/dist/da-DK.module.js +0 -16
  33. package/dist/da-DK.module.js.map +0 -1
  34. package/dist/de-DE.main.js +0 -14
  35. package/dist/de-DE.main.js.map +0 -1
  36. package/dist/de-DE.mjs +0 -16
  37. package/dist/de-DE.module.js +0 -16
  38. package/dist/de-DE.module.js.map +0 -1
  39. package/dist/el-GR.main.js +0 -14
  40. package/dist/el-GR.main.js.map +0 -1
  41. package/dist/el-GR.mjs +0 -16
  42. package/dist/el-GR.module.js +0 -16
  43. package/dist/el-GR.module.js.map +0 -1
  44. package/dist/en-US.main.js +0 -14
  45. package/dist/en-US.main.js.map +0 -1
  46. package/dist/en-US.mjs +0 -16
  47. package/dist/en-US.module.js +0 -16
  48. package/dist/en-US.module.js.map +0 -1
  49. package/dist/es-ES.main.js +0 -14
  50. package/dist/es-ES.main.js.map +0 -1
  51. package/dist/es-ES.mjs +0 -16
  52. package/dist/es-ES.module.js +0 -16
  53. package/dist/es-ES.module.js.map +0 -1
  54. package/dist/et-EE.main.js +0 -14
  55. package/dist/et-EE.main.js.map +0 -1
  56. package/dist/et-EE.mjs +0 -16
  57. package/dist/et-EE.module.js +0 -16
  58. package/dist/et-EE.module.js.map +0 -1
  59. package/dist/fi-FI.main.js +0 -14
  60. package/dist/fi-FI.main.js.map +0 -1
  61. package/dist/fi-FI.mjs +0 -16
  62. package/dist/fi-FI.module.js +0 -16
  63. package/dist/fi-FI.module.js.map +0 -1
  64. package/dist/fr-FR.main.js +0 -14
  65. package/dist/fr-FR.main.js.map +0 -1
  66. package/dist/fr-FR.mjs +0 -16
  67. package/dist/fr-FR.module.js +0 -16
  68. package/dist/fr-FR.module.js.map +0 -1
  69. package/dist/he-IL.main.js +0 -14
  70. package/dist/he-IL.main.js.map +0 -1
  71. package/dist/he-IL.mjs +0 -16
  72. package/dist/he-IL.module.js +0 -16
  73. package/dist/he-IL.module.js.map +0 -1
  74. package/dist/hr-HR.main.js +0 -14
  75. package/dist/hr-HR.main.js.map +0 -1
  76. package/dist/hr-HR.mjs +0 -16
  77. package/dist/hr-HR.module.js +0 -16
  78. package/dist/hr-HR.module.js.map +0 -1
  79. package/dist/hu-HU.main.js +0 -14
  80. package/dist/hu-HU.main.js.map +0 -1
  81. package/dist/hu-HU.mjs +0 -16
  82. package/dist/hu-HU.module.js +0 -16
  83. package/dist/hu-HU.module.js.map +0 -1
  84. package/dist/intlStrings.main.js +0 -108
  85. package/dist/intlStrings.main.js.map +0 -1
  86. package/dist/intlStrings.mjs +0 -110
  87. package/dist/intlStrings.module.js +0 -110
  88. package/dist/intlStrings.module.js.map +0 -1
  89. package/dist/it-IT.main.js +0 -14
  90. package/dist/it-IT.main.js.map +0 -1
  91. package/dist/it-IT.mjs +0 -16
  92. package/dist/it-IT.module.js +0 -16
  93. package/dist/it-IT.module.js.map +0 -1
  94. package/dist/ja-JP.main.js +0 -14
  95. package/dist/ja-JP.main.js.map +0 -1
  96. package/dist/ja-JP.mjs +0 -16
  97. package/dist/ja-JP.module.js +0 -16
  98. package/dist/ja-JP.module.js.map +0 -1
  99. package/dist/ko-KR.main.js +0 -14
  100. package/dist/ko-KR.main.js.map +0 -1
  101. package/dist/ko-KR.mjs +0 -16
  102. package/dist/ko-KR.module.js +0 -16
  103. package/dist/ko-KR.module.js.map +0 -1
  104. package/dist/lt-LT.main.js +0 -14
  105. package/dist/lt-LT.main.js.map +0 -1
  106. package/dist/lt-LT.mjs +0 -16
  107. package/dist/lt-LT.module.js +0 -16
  108. package/dist/lt-LT.module.js.map +0 -1
  109. package/dist/lv-LV.main.js +0 -14
  110. package/dist/lv-LV.main.js.map +0 -1
  111. package/dist/lv-LV.mjs +0 -16
  112. package/dist/lv-LV.module.js +0 -16
  113. package/dist/lv-LV.module.js.map +0 -1
  114. package/dist/nb-NO.main.js +0 -14
  115. package/dist/nb-NO.main.js.map +0 -1
  116. package/dist/nb-NO.mjs +0 -16
  117. package/dist/nb-NO.module.js +0 -16
  118. package/dist/nb-NO.module.js.map +0 -1
  119. package/dist/nl-NL.main.js +0 -14
  120. package/dist/nl-NL.main.js.map +0 -1
  121. package/dist/nl-NL.mjs +0 -16
  122. package/dist/nl-NL.module.js +0 -16
  123. package/dist/nl-NL.module.js.map +0 -1
  124. package/dist/pl-PL.main.js +0 -14
  125. package/dist/pl-PL.main.js.map +0 -1
  126. package/dist/pl-PL.mjs +0 -16
  127. package/dist/pl-PL.module.js +0 -16
  128. package/dist/pl-PL.module.js.map +0 -1
  129. package/dist/pt-BR.main.js +0 -14
  130. package/dist/pt-BR.main.js.map +0 -1
  131. package/dist/pt-BR.mjs +0 -16
  132. package/dist/pt-BR.module.js +0 -16
  133. package/dist/pt-BR.module.js.map +0 -1
  134. package/dist/pt-PT.main.js +0 -14
  135. package/dist/pt-PT.main.js.map +0 -1
  136. package/dist/pt-PT.mjs +0 -16
  137. package/dist/pt-PT.module.js +0 -16
  138. package/dist/pt-PT.module.js.map +0 -1
  139. package/dist/ro-RO.main.js +0 -14
  140. package/dist/ro-RO.main.js.map +0 -1
  141. package/dist/ro-RO.mjs +0 -16
  142. package/dist/ro-RO.module.js +0 -16
  143. package/dist/ro-RO.module.js.map +0 -1
  144. package/dist/ru-RU.main.js +0 -14
  145. package/dist/ru-RU.main.js.map +0 -1
  146. package/dist/ru-RU.mjs +0 -16
  147. package/dist/ru-RU.module.js +0 -16
  148. package/dist/ru-RU.module.js.map +0 -1
  149. package/dist/sk-SK.main.js +0 -14
  150. package/dist/sk-SK.main.js.map +0 -1
  151. package/dist/sk-SK.mjs +0 -16
  152. package/dist/sk-SK.module.js +0 -16
  153. package/dist/sk-SK.module.js.map +0 -1
  154. package/dist/sl-SI.main.js +0 -14
  155. package/dist/sl-SI.main.js.map +0 -1
  156. package/dist/sl-SI.mjs +0 -16
  157. package/dist/sl-SI.module.js +0 -16
  158. package/dist/sl-SI.module.js.map +0 -1
  159. package/dist/sr-SP.main.js +0 -14
  160. package/dist/sr-SP.main.js.map +0 -1
  161. package/dist/sr-SP.mjs +0 -16
  162. package/dist/sr-SP.module.js +0 -16
  163. package/dist/sr-SP.module.js.map +0 -1
  164. package/dist/sv-SE.main.js +0 -14
  165. package/dist/sv-SE.main.js.map +0 -1
  166. package/dist/sv-SE.mjs +0 -16
  167. package/dist/sv-SE.module.js +0 -16
  168. package/dist/sv-SE.module.js.map +0 -1
  169. package/dist/tr-TR.main.js +0 -14
  170. package/dist/tr-TR.main.js.map +0 -1
  171. package/dist/tr-TR.mjs +0 -16
  172. package/dist/tr-TR.module.js +0 -16
  173. package/dist/tr-TR.module.js.map +0 -1
  174. package/dist/types.d.ts +0 -157
  175. package/dist/types.d.ts.map +0 -1
  176. package/dist/uk-UA.main.js +0 -14
  177. package/dist/uk-UA.main.js.map +0 -1
  178. package/dist/uk-UA.mjs +0 -16
  179. package/dist/uk-UA.module.js +0 -16
  180. package/dist/uk-UA.module.js.map +0 -1
  181. package/dist/useTable.main.js +0 -114
  182. package/dist/useTable.main.js.map +0 -1
  183. package/dist/useTable.mjs +0 -109
  184. package/dist/useTable.module.js +0 -109
  185. package/dist/useTable.module.js.map +0 -1
  186. package/dist/useTableCell.main.js +0 -37
  187. package/dist/useTableCell.main.js.map +0 -1
  188. package/dist/useTableCell.mjs +0 -32
  189. package/dist/useTableCell.module.js +0 -32
  190. package/dist/useTableCell.module.js.map +0 -1
  191. package/dist/useTableColumnHeader.main.js +0 -92
  192. package/dist/useTableColumnHeader.main.js.map +0 -1
  193. package/dist/useTableColumnHeader.mjs +0 -87
  194. package/dist/useTableColumnHeader.module.js +0 -87
  195. package/dist/useTableColumnHeader.module.js.map +0 -1
  196. package/dist/useTableColumnResize.main.js +0 -226
  197. package/dist/useTableColumnResize.main.js.map +0 -1
  198. package/dist/useTableColumnResize.mjs +0 -221
  199. package/dist/useTableColumnResize.module.js +0 -221
  200. package/dist/useTableColumnResize.module.js.map +0 -1
  201. package/dist/useTableHeaderRow.main.js +0 -32
  202. package/dist/useTableHeaderRow.main.js.map +0 -1
  203. package/dist/useTableHeaderRow.mjs +0 -27
  204. package/dist/useTableHeaderRow.module.js +0 -27
  205. package/dist/useTableHeaderRow.module.js.map +0 -1
  206. package/dist/useTableRow.main.js +0 -82
  207. package/dist/useTableRow.main.js.map +0 -1
  208. package/dist/useTableRow.mjs +0 -77
  209. package/dist/useTableRow.module.js +0 -77
  210. package/dist/useTableRow.module.js.map +0 -1
  211. package/dist/useTableSelectionCheckbox.main.js +0 -56
  212. package/dist/useTableSelectionCheckbox.main.js.map +0 -1
  213. package/dist/useTableSelectionCheckbox.mjs +0 -50
  214. package/dist/useTableSelectionCheckbox.module.js +0 -50
  215. package/dist/useTableSelectionCheckbox.module.js.map +0 -1
  216. package/dist/utils.main.js +0 -43
  217. package/dist/utils.main.js.map +0 -1
  218. package/dist/utils.mjs +0 -35
  219. package/dist/utils.module.js +0 -35
  220. package/dist/utils.module.js.map +0 -1
  221. package/dist/zh-CN.main.js +0 -14
  222. package/dist/zh-CN.main.js.map +0 -1
  223. package/dist/zh-CN.mjs +0 -16
  224. package/dist/zh-CN.module.js +0 -16
  225. package/dist/zh-CN.module.js.map +0 -1
  226. package/dist/zh-TW.main.js +0 -14
  227. package/dist/zh-TW.main.js.map +0 -1
  228. package/dist/zh-TW.mjs +0 -16
  229. package/dist/zh-TW.module.js +0 -16
  230. package/dist/zh-TW.module.js.map +0 -1
  231. package/src/TableKeyboardDelegate.ts +0 -214
  232. package/src/useTable.ts +0 -123
  233. package/src/useTableCell.ts +0 -59
  234. package/src/useTableColumnHeader.ts +0 -108
  235. package/src/useTableColumnResize.ts +0 -277
  236. package/src/useTableHeaderRow.ts +0 -42
  237. package/src/useTableRow.ts +0 -86
  238. package/src/useTableSelectionCheckbox.ts +0 -72
  239. package/src/utils.ts +0 -49
package/src/useTable.ts DELETED
@@ -1,123 +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 {announce} from '@react-aria/live-announcer';
14
- import {GridAria, GridProps, useGrid} from '@react-aria/grid';
15
- import {gridIds} from './utils';
16
- // @ts-ignore
17
- import intlMessages from '../intl/*.json';
18
- import {Key, LayoutDelegate, Rect, RefObject, Size} from '@react-types/shared';
19
- import {mergeProps, useDescription, useId, useUpdateEffect} from '@react-aria/utils';
20
- import {TableKeyboardDelegate} from './TableKeyboardDelegate';
21
- import {tableNestedRows} from '@react-stately/flags';
22
- import {TableState, TreeGridState} from '@react-stately/table';
23
- import {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
24
- import {useMemo} from 'react';
25
-
26
- export interface AriaTableProps extends GridProps {
27
- /** The layout object for the table. Computes what content is visible and how to position and style them. */
28
- layoutDelegate?: LayoutDelegate,
29
- /** @deprecated - Use layoutDelegate instead. */
30
- layout?: DeprecatedLayout
31
- }
32
-
33
- interface DeprecatedLayout {
34
- getLayoutInfo(key: Key): DeprecatedLayoutInfo,
35
- getContentSize(): Size,
36
- virtualizer: DeprecatedVirtualizer
37
- }
38
-
39
- interface DeprecatedLayoutInfo {
40
- rect: Rect
41
- }
42
-
43
- interface DeprecatedVirtualizer {
44
- visibleRect: Rect
45
- }
46
-
47
- /**
48
- * Provides the behavior and accessibility implementation for a table component.
49
- * A table displays data in rows and columns and enables a user to navigate its contents via directional navigation keys,
50
- * and optionally supports row selection and sorting.
51
- * @param props - Props for the table.
52
- * @param state - State for the table, as returned by `useTableState`.
53
- * @param ref - The ref attached to the table element.
54
- */
55
- export function useTable<T>(props: AriaTableProps, state: TableState<T> | TreeGridState<T>, ref: RefObject<HTMLElement | null>): GridAria {
56
- let {
57
- keyboardDelegate,
58
- isVirtualized,
59
- layoutDelegate,
60
- layout
61
- } = props;
62
-
63
- // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
64
- // When virtualized, the layout object will be passed in as a prop and override this.
65
- let collator = useCollator({usage: 'search', sensitivity: 'base'});
66
- let {direction} = useLocale();
67
- let disabledBehavior = state.selectionManager.disabledBehavior;
68
- let delegate = useMemo(() => keyboardDelegate || new TableKeyboardDelegate({
69
- collection: state.collection,
70
- disabledKeys: state.disabledKeys,
71
- disabledBehavior,
72
- ref,
73
- direction,
74
- collator,
75
- layoutDelegate,
76
- layout
77
- }), [keyboardDelegate, state.collection, state.disabledKeys, disabledBehavior, ref, direction, collator, layoutDelegate, layout]);
78
- let id = useId(props.id);
79
- gridIds.set(state, id);
80
-
81
- let {gridProps} = useGrid({
82
- ...props,
83
- id,
84
- keyboardDelegate: delegate
85
- }, state, ref);
86
-
87
- // Override to include header rows
88
- if (isVirtualized) {
89
- gridProps['aria-rowcount'] = state.collection.size + state.collection.headerRows.length;
90
- }
91
-
92
- if (tableNestedRows() && 'expandedKeys' in state) {
93
- gridProps.role = 'treegrid';
94
- }
95
-
96
- let {column, direction: sortDirection} = state.sortDescriptor || {};
97
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');
98
- let sortDescription = useMemo(() => {
99
- let columnName = state.collection.columns.find(c => c.key === column)?.textValue ?? '';
100
- return sortDirection && column ? stringFormatter.format(`${sortDirection}Sort`, {columnName}) : undefined;
101
- // eslint-disable-next-line react-hooks/exhaustive-deps
102
- }, [sortDirection, column, state.collection.columns]);
103
-
104
- let descriptionProps = useDescription(sortDescription);
105
-
106
- // Only announce after initial render, tabbing to the table will tell you the initial sort info already
107
- useUpdateEffect(() => {
108
- if (sortDescription) {
109
- announce(sortDescription, 'assertive', 500);
110
- }
111
- }, [sortDescription]);
112
-
113
- return {
114
- gridProps: mergeProps(
115
- gridProps,
116
- descriptionProps,
117
- {
118
- // merge sort description with long press information
119
- 'aria-describedby': [descriptionProps['aria-describedby'], gridProps['aria-describedby']].filter(Boolean).join(' ')
120
- }
121
- )
122
- };
123
- }
@@ -1,59 +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, RefObject} from '@react-types/shared';
14
- import {getCellId} from './utils';
15
- import {GridNode} from '@react-types/grid';
16
- import {TableState} from '@react-stately/table';
17
- import {useGridCell} from '@react-aria/grid';
18
-
19
- export interface AriaTableCellProps {
20
- /** An object representing the table cell. Contains all the relevant information that makes up the row header. */
21
- node: GridNode<unknown>,
22
- /** Whether the cell is contained in a virtual scroller. */
23
- isVirtualized?: boolean,
24
- /** Whether selection should occur on press up instead of press down. */
25
- shouldSelectOnPressUp?: boolean,
26
- /**
27
- * Handler that is called when a user performs an action on the cell.
28
- * Please use onCellAction at the collection level instead.
29
- * @deprecated
30
- **/
31
- onAction?: () => void
32
- }
33
-
34
- export interface TableCellAria {
35
- /** Props for the table cell element. */
36
- gridCellProps: DOMAttributes,
37
- /** Whether the cell is currently in a pressed state. */
38
- isPressed: boolean
39
- }
40
-
41
- /**
42
- * Provides the behavior and accessibility implementation for a cell in a table.
43
- * @param props - Props for the cell.
44
- * @param state - State of the table, as returned by `useTableState`.
45
- * @param ref - The ref attached to the cell element.
46
- */
47
- export function useTableCell<T>(props: AriaTableCellProps, state: TableState<T>, ref: RefObject<FocusableElement | null>): TableCellAria {
48
- let {gridCellProps, isPressed} = useGridCell(props, state, ref);
49
- let columnKey = props.node.column?.key;
50
- if (columnKey != null && state.collection.rowHeaderColumnKeys.has(columnKey)) {
51
- gridCellProps.role = 'rowheader';
52
- gridCellProps.id = getCellId(state, props.node.parentKey!, columnKey);
53
- }
54
-
55
- return {
56
- gridCellProps,
57
- isPressed
58
- };
59
- }
@@ -1,108 +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, RefObject} from '@react-types/shared';
14
- import {getColumnHeaderId} from './utils';
15
- import {GridNode} from '@react-types/grid';
16
- // @ts-ignore
17
- import intlMessages from '../intl/*.json';
18
- import {isAndroid, mergeProps, useDescription} from '@react-aria/utils';
19
- import {TableState} from '@react-stately/table';
20
- import {useEffect} from 'react';
21
- import {useFocusable, usePress} from '@react-aria/interactions';
22
- import {useGridCell} from '@react-aria/grid';
23
- import {useLocalizedStringFormatter} from '@react-aria/i18n';
24
-
25
- export interface AriaTableColumnHeaderProps<T> {
26
- /** An object representing the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader). Contains all the relevant information that makes up the column header. */
27
- node: GridNode<T>,
28
- /** Whether the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader) is contained in a virtual scroller. */
29
- isVirtualized?: boolean
30
- }
31
-
32
- export interface TableColumnHeaderAria {
33
- /** Props for the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader) element. */
34
- columnHeaderProps: DOMAttributes,
35
- /** Whether the column is currently in a pressed state. */
36
- isPressed: boolean
37
- }
38
-
39
- /**
40
- * Provides the behavior and accessibility implementation for a column header in a table.
41
- * @param props - Props for the column header.
42
- * @param state - State of the table, as returned by `useTableState`.
43
- * @param ref - The ref attached to the column header element.
44
- */
45
- export function useTableColumnHeader<T>(props: AriaTableColumnHeaderProps<T>, state: TableState<T>, ref: RefObject<FocusableElement | null>): TableColumnHeaderAria {
46
- let {node} = props;
47
- let allowsSorting = node.props.allowsSorting;
48
- // if there are no focusable children, the column header will focus the cell
49
- let {gridCellProps} = useGridCell({...props, focusMode: 'child'}, state, ref);
50
-
51
- let isSelectionCellDisabled = node.props.isSelectionCell && state.selectionManager.selectionMode === 'single';
52
-
53
- let {pressProps, isPressed} = usePress({
54
- isDisabled: !allowsSorting || isSelectionCellDisabled,
55
- onPress() {
56
- state.sort(node.key);
57
- },
58
- ref
59
- });
60
-
61
- // Needed to pick up the focusable context, enabling things like Tooltips for example
62
- let {focusableProps} = useFocusable({}, ref);
63
-
64
- let ariaSort: DOMAttributes['aria-sort'] | undefined = undefined;
65
- let isSortedColumn = state.sortDescriptor?.column === node.key;
66
- let sortDirection = state.sortDescriptor?.direction;
67
- // aria-sort not supported in Android Talkback
68
- if (node.props.allowsSorting && !isAndroid()) {
69
- ariaSort = isSortedColumn ? sortDirection : 'none';
70
- }
71
-
72
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');
73
- let sortDescription;
74
- if (allowsSorting) {
75
- sortDescription = `${stringFormatter.format('sortable')}`;
76
- // Android Talkback doesn't support aria-sort so we add sort order details to the aria-described by here
77
- if (isSortedColumn && sortDirection && isAndroid()) {
78
- sortDescription = `${sortDescription}, ${stringFormatter.format(sortDirection)}`;
79
- }
80
- }
81
-
82
- let descriptionProps = useDescription(sortDescription);
83
-
84
- let shouldDisableFocus = state.collection.size === 0;
85
- useEffect(() => {
86
- if (shouldDisableFocus && state.selectionManager.focusedKey === node.key) {
87
- state.selectionManager.setFocusedKey(null);
88
- }
89
- }, [shouldDisableFocus, state.selectionManager, node.key]);
90
-
91
- return {
92
- columnHeaderProps: {
93
- ...mergeProps(
94
- focusableProps,
95
- gridCellProps,
96
- pressProps,
97
- descriptionProps,
98
- // If the table is empty, make all column headers untabbable
99
- shouldDisableFocus ? {tabIndex: -1} : null
100
- ),
101
- role: 'columnheader',
102
- id: getColumnHeaderId(state, node.key),
103
- 'aria-colspan': node.colSpan && node.colSpan > 1 ? node.colSpan : undefined,
104
- 'aria-sort': ariaSort
105
- },
106
- isPressed
107
- };
108
- }
@@ -1,277 +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 {ChangeEvent, useCallback, useEffect, useRef} from 'react';
14
- import {ColumnSize} from '@react-types/table';
15
- import {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';
16
- import {focusSafely, useInteractionModality, useKeyboard, useMove, usePress} from '@react-aria/interactions';
17
- import {getColumnHeaderId} from './utils';
18
- import {GridNode} from '@react-types/grid';
19
- // @ts-ignore
20
- import intlMessages from '../intl/*.json';
21
- import {mergeProps, useDescription, useEffectEvent, useId} from '@react-aria/utils';
22
- import {TableColumnResizeState} from '@react-stately/table';
23
- import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
24
- import {useVisuallyHidden} from '@react-aria/visually-hidden';
25
-
26
- export interface TableColumnResizeAria {
27
- /** Props for the visually hidden input element. */
28
- inputProps: DOMAttributes,
29
- /** Props for the resizer element. */
30
- resizerProps: DOMAttributes,
31
- /** Whether this column is currently being resized. */
32
- isResizing: boolean
33
- }
34
-
35
- export interface AriaTableColumnResizeProps<T> {
36
- /** An object representing the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader). Contains all the relevant information that makes up the column header. */
37
- column: GridNode<T>,
38
- /** Aria label for the hidden input. Gets read when resizing. */
39
- 'aria-label': string,
40
- /**
41
- * Ref to the trigger if resizing was started from a column header menu. If it's provided,
42
- * focus will be returned there when resizing is done. If it isn't provided, it is assumed that the resizer is
43
- * visible at all time and keyboard resizing is started via pressing Enter on the resizer and not on focus.
44
- * */
45
- triggerRef?: RefObject<FocusableElement | null>,
46
- /** If resizing is disabled. */
47
- isDisabled?: boolean,
48
- /** Called when resizing starts. */
49
- onResizeStart?: (widths: Map<Key, ColumnSize>) => void,
50
- /** Called for every resize event that results in new column sizes. */
51
- onResize?: (widths: Map<Key, ColumnSize>) => void,
52
- /** Called when resizing ends. */
53
- onResizeEnd?: (widths: Map<Key, ColumnSize>) => void
54
- }
55
-
56
- /**
57
- * Provides the behavior and accessibility implementation for a table column resizer element.
58
- * @param props - Props for the resizer.
59
- * @param state - State for the table's resizable columns, as returned by `useTableColumnResizeState`.
60
- * @param ref - The ref attached to the resizer's visually hidden input element.
61
- */
62
- export function useTableColumnResize<T>(props: AriaTableColumnResizeProps<T>, state: TableColumnResizeState<T>, ref: RefObject<HTMLInputElement | null>): TableColumnResizeAria {
63
- let {column: item, triggerRef, isDisabled, onResizeStart, onResize, onResizeEnd, 'aria-label': ariaLabel} = props;
64
- const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');
65
- let id = useId();
66
- let isResizing = state.resizingColumn === item.key;
67
- let isResizingRef = useRef(isResizing);
68
- let lastSize = useRef<Map<Key, ColumnSize> | null>(null);
69
- let wasFocusedOnResizeStart = useRef(false);
70
- let editModeEnabled = state.tableState.isKeyboardNavigationDisabled;
71
-
72
- let {direction} = useLocale();
73
-
74
- let startResize = useCallback((item) => {
75
- if (!isResizingRef.current) {
76
- lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));
77
- state.startResize(item.key);
78
- state.tableState.setKeyboardNavigationDisabled(true);
79
- onResizeStart?.(lastSize.current);
80
- }
81
- isResizingRef.current = true;
82
- }, [state, onResizeStart]);
83
-
84
- let resize = useCallback((item, newWidth) => {
85
- let sizes = state.updateResizedColumns(item.key, newWidth);
86
- onResize?.(sizes);
87
- lastSize.current = sizes;
88
- }, [state, onResize]);
89
-
90
- let endResize = useCallback((item) => {
91
- if (isResizingRef.current) {
92
- if (lastSize.current == null) {
93
- lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));
94
- }
95
-
96
- state.endResize();
97
- state.tableState.setKeyboardNavigationDisabled(false);
98
- onResizeEnd?.(lastSize.current);
99
- isResizingRef.current = false;
100
-
101
- if (triggerRef?.current && !wasFocusedOnResizeStart.current) {
102
- // switch focus back to the column header unless the resizer was already focused when resizing started.
103
- focusSafely(triggerRef.current);
104
- }
105
- }
106
- lastSize.current = null;
107
- }, [state, triggerRef, onResizeEnd]);
108
-
109
- let {keyboardProps} = useKeyboard({
110
- onKeyDown: (e) => {
111
- if (editModeEnabled) {
112
- if (e.key === 'Escape' || e.key === 'Enter' || e.key === ' ' || e.key === 'Tab') {
113
- e.preventDefault();
114
- endResize(item);
115
- }
116
- } else {
117
- // Continue propagation on keydown events so they still bubbles to useSelectableCollection and are handled there
118
- e.continuePropagation();
119
-
120
- if (e.key === 'Enter') {
121
- startResize(item);
122
- }
123
- }
124
- }
125
- });
126
-
127
- const columnResizeWidthRef = useRef<number>(0);
128
- const {moveProps} = useMove({
129
- onMoveStart() {
130
- columnResizeWidthRef.current = state.getColumnWidth(item.key);
131
- startResize(item);
132
- },
133
- onMove(e) {
134
- let {deltaX, deltaY, pointerType} = e;
135
- if (direction === 'rtl') {
136
- deltaX *= -1;
137
- }
138
- if (pointerType === 'keyboard') {
139
- if (deltaY !== 0 && deltaX === 0) {
140
- deltaX = deltaY * -1;
141
- }
142
- deltaX *= 10;
143
- }
144
- // if moving up/down only, no need to resize
145
- if (deltaX !== 0) {
146
- columnResizeWidthRef.current += deltaX;
147
- resize(item, columnResizeWidthRef.current);
148
- }
149
- },
150
- onMoveEnd(e) {
151
- let {pointerType} = e;
152
- columnResizeWidthRef.current = 0;
153
- if (pointerType === 'mouse' || (pointerType === 'touch' && wasFocusedOnResizeStart.current)) {
154
- endResize(item);
155
- }
156
- }
157
- });
158
-
159
- let onKeyDown = useCallback((e) => {
160
- if (editModeEnabled) {
161
- moveProps.onKeyDown?.(e);
162
- }
163
- }, [editModeEnabled, moveProps]);
164
-
165
-
166
- let min = Math.floor(state.getColumnMinWidth(item.key));
167
- let max = Math.floor(state.getColumnMaxWidth(item.key));
168
- if (max === Infinity) {
169
- max = Number.MAX_SAFE_INTEGER;
170
- }
171
- let value = Math.floor(state.getColumnWidth(item.key));
172
- let modality: string | null = useInteractionModality();
173
- if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {
174
- modality = 'touch';
175
- }
176
- let description = triggerRef?.current == null && (modality === 'keyboard' || modality === 'virtual') && !isResizing ? stringFormatter.format('resizerDescription') : undefined;
177
- let descriptionProps = useDescription(description);
178
- let ariaProps = {
179
- 'aria-label': ariaLabel,
180
- 'aria-orientation': 'horizontal' as 'horizontal',
181
- 'aria-labelledby': `${id} ${getColumnHeaderId(state.tableState, item.key)}`,
182
- 'aria-valuetext': stringFormatter.format('columnSize', {value}),
183
- 'type': 'range',
184
- min,
185
- max,
186
- value,
187
- ...descriptionProps
188
- };
189
-
190
- const focusInput = useCallback(() => {
191
- if (ref.current) {
192
- focusSafely(ref.current);
193
- }
194
- }, [ref]);
195
-
196
- let resizingColumn = state.resizingColumn;
197
- let prevResizingColumn = useRef<Key | null>(null);
198
- let startResizeEvent = useEffectEvent(startResize);
199
- useEffect(() => {
200
- if (prevResizingColumn.current !== resizingColumn && resizingColumn != null && resizingColumn === item.key) {
201
- wasFocusedOnResizeStart.current = document.activeElement === ref.current;
202
- startResizeEvent(item);
203
- // Delay focusing input until Android Chrome's delayed click after touchend happens: https://bugs.chromium.org/p/chromium/issues/detail?id=1150073
204
- let timeout = setTimeout(() => focusInput(), 0);
205
- // VoiceOver on iOS has problems focusing the input from a menu.
206
- let VOTimeout = setTimeout(focusInput, 400);
207
- return () => {
208
- clearTimeout(timeout);
209
- clearTimeout(VOTimeout);
210
- };
211
- }
212
- prevResizingColumn.current = resizingColumn;
213
- }, [resizingColumn, item, focusInput, ref]);
214
-
215
- let onChange = (e: ChangeEvent<HTMLInputElement>) => {
216
- let currentWidth = state.getColumnWidth(item.key);
217
- let nextValue = parseFloat(e.target.value);
218
-
219
- if (nextValue > currentWidth) {
220
- nextValue = currentWidth + 10;
221
- } else {
222
- nextValue = currentWidth - 10;
223
- }
224
- resize(item, nextValue);
225
- };
226
-
227
- let {pressProps} = usePress({
228
- preventFocusOnPress: true,
229
- onPressStart: (e) => {
230
- if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey || e.pointerType === 'keyboard') {
231
- return;
232
- }
233
- if (e.pointerType === 'virtual' && state.resizingColumn != null) {
234
- endResize(item);
235
- return;
236
- }
237
-
238
- // Sometimes onPress won't trigger for quick taps on mobile so we want to focus the input so blurring away
239
- // can cancel resize mode for us.
240
- focusInput();
241
-
242
- // If resizer is always visible, mobile screenreader user can access the visually hidden resizer directly and thus we don't need
243
- // to handle a virtual click to start the resizer.
244
- if (e.pointerType !== 'virtual') {
245
- startResize(item);
246
- }
247
- },
248
- onPress: (e) => {
249
- if (((e.pointerType === 'touch' && wasFocusedOnResizeStart.current) || e.pointerType === 'mouse') && state.resizingColumn != null) {
250
- endResize(item);
251
- }
252
- }
253
- });
254
- let {visuallyHiddenProps} = useVisuallyHidden();
255
-
256
- return {
257
- resizerProps: mergeProps(
258
- keyboardProps,
259
- {...moveProps, onKeyDown},
260
- pressProps,
261
- {style: {touchAction: 'none'}}
262
- ),
263
- inputProps: mergeProps(
264
- visuallyHiddenProps,
265
- {
266
- id,
267
- onBlur: () => {
268
- endResize(item);
269
- },
270
- onChange,
271
- disabled: isDisabled
272
- },
273
- ariaProps
274
- ),
275
- isResizing
276
- };
277
- }
@@ -1,42 +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, RefObject} from '@react-types/shared';
14
- import {GridRowProps} from '@react-aria/grid';
15
- import {tableNestedRows} from '@react-stately/flags';
16
- import {TableState} from '@react-stately/table';
17
-
18
- export interface TableHeaderRowAria {
19
- /** Props for the grid row element. */
20
- rowProps: DOMAttributes
21
- }
22
-
23
- /**
24
- * Provides the behavior and accessibility implementation for a header row in a table.
25
- * @param props - Props for the row.
26
- * @param state - State of the table, as returned by `useTableState`.
27
- */
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- export function useTableHeaderRow<T>(props: GridRowProps<T>, state: TableState<T>, ref: RefObject<Element | null>): TableHeaderRowAria {
30
- let {node, isVirtualized} = props;
31
- let rowProps = {
32
- role: 'row'
33
- };
34
-
35
- if (isVirtualized && !(tableNestedRows() && 'expandedKeys' in state)) {
36
- rowProps['aria-rowindex'] = node.index + 1; // aria-rowindex is 1 based
37
- }
38
-
39
- return {
40
- rowProps
41
- };
42
- }