( props: GridRowProps<T>, state: TableState<T> | TreeGridState<T>, ref: RefObject<FocusableElement | null> )
| 48 | * @param state - State of the table, as returned by `useTableState`. |
| 49 | */ |
| 50 | export function useTableRow<T>( |
| 51 | props: GridRowProps<T>, |
| 52 | state: TableState<T> | TreeGridState<T>, |
| 53 | ref: RefObject<FocusableElement | null> |
| 54 | ): TableRowAria { |
| 55 | let {node, isVirtualized} = props; |
| 56 | let {rowProps, ...states} = useGridRow<T, ITableCollection<T>, TableState<T>>( |
| 57 | props, |
| 58 | state as TableState<T>, |
| 59 | ref |
| 60 | ); |
| 61 | let {direction} = useLocale(); |
| 62 | |
| 63 | if (isVirtualized && state.treeColumn == null) { |
| 64 | rowProps['aria-rowindex'] = node.index + 1 + state.collection.headerRows.length; // aria-rowindex is 1 based |
| 65 | } else { |
| 66 | delete rowProps['aria-rowindex']; |
| 67 | } |
| 68 | |
| 69 | let isExpanded = |
| 70 | state.treeColumn != null && (state.expandedKeys === 'all' || state.expandedKeys.has(node.key)); |
| 71 | let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table'); |
| 72 | let labelProps = useLabels({ |
| 73 | 'aria-label': isExpanded |
| 74 | ? stringFormatter.format('collapse') |
| 75 | : stringFormatter.format('expand'), |
| 76 | 'aria-labelledby': getRowLabelledBy(state as TableState<T>, node.key) |
| 77 | }); |
| 78 | |
| 79 | let treeGridRowProps: HTMLAttributes<HTMLElement> = {}; |
| 80 | let expandButtonProps: AriaButtonProps = {}; |
| 81 | if (state.treeColumn != null) { |
| 82 | let treeNode = state.collection.getItem(node.key); |
| 83 | if (treeNode != null) { |
| 84 | let lastChild = getLastChild(state.collection, node); |
| 85 | let hasChildRows = |
| 86 | treeNode.props?.hasChildRows || |
| 87 | treeNode.props?.UNSTABLE_childItems || |
| 88 | lastChild?.type !== 'cell'; |
| 89 | let parent = state.collection.getItem(node.parentKey!)!; |
| 90 | let isParentBody = parent.type === 'tablebody' || parent.type === 'body'; |
| 91 | let lastSibling = getLastChild(state.collection, parent)!; |
| 92 | while (lastSibling && lastSibling.type !== 'item' && lastSibling.prevKey != null) { |
| 93 | lastSibling = state.collection.getItem(lastSibling.prevKey)!; |
| 94 | } |
| 95 | |
| 96 | treeGridRowProps = { |
| 97 | onKeyDown: e => { |
| 98 | if ( |
| 99 | e.key === EXPANSION_KEYS['expand'][direction] && |
| 100 | state.selectionManager.focusedKey === treeNode.key && |
| 101 | hasChildRows && |
| 102 | state.expandedKeys !== 'all' && |
| 103 | !state.expandedKeys.has(treeNode.key) |
| 104 | ) { |
| 105 | state.toggleKey(treeNode.key); |
| 106 | e.stopPropagation(); |
| 107 | } else if ( |
no test coverage detected