( props: GridRowProps<T>, state: S, ref: RefObject<FocusableElement | null> )
| 54 | * @param state - State of the parent grid, as returned by `useGridState`. |
| 55 | */ |
| 56 | export function useGridRow<T, C extends GridCollection<T>, S extends GridState<T, C>>( |
| 57 | props: GridRowProps<T>, |
| 58 | state: S, |
| 59 | ref: RefObject<FocusableElement | null> |
| 60 | ): GridRowAria { |
| 61 | let {node, isVirtualized, shouldSelectOnPressUp, onAction} = props; |
| 62 | |
| 63 | let {actions, shouldSelectOnPressUp: gridShouldSelectOnPressUp} = gridMap.get(state)!; |
| 64 | let onRowAction = actions.onRowAction ? () => actions.onRowAction?.(node.key) : onAction; |
| 65 | let {itemProps, ...states} = useSelectableItem({ |
| 66 | selectionManager: state.selectionManager, |
| 67 | key: node.key, |
| 68 | ref, |
| 69 | isVirtualized, |
| 70 | shouldSelectOnPressUp: gridShouldSelectOnPressUp || shouldSelectOnPressUp, |
| 71 | onAction: |
| 72 | onRowAction || node?.props?.onAction ? chain(node?.props?.onAction, onRowAction) : undefined, |
| 73 | isDisabled: state.collection.size === 0 |
| 74 | }); |
| 75 | |
| 76 | let isSelected = state.selectionManager.isSelected(node.key); |
| 77 | |
| 78 | let rowProps: DOMAttributes = { |
| 79 | role: 'row', |
| 80 | 'aria-selected': state.selectionManager.selectionMode !== 'none' ? isSelected : undefined, |
| 81 | 'aria-disabled': states.isDisabled || undefined, |
| 82 | ...itemProps |
| 83 | }; |
| 84 | |
| 85 | if (isVirtualized) { |
| 86 | rowProps['aria-rowindex'] = node.index + 1; // aria-rowindex is 1 based |
| 87 | } |
| 88 | |
| 89 | return { |
| 90 | rowProps, |
| 91 | ...states |
| 92 | }; |
| 93 | } |
no test coverage detected