Skip to content

Adding feature flag check for expandable table rows in aria hooks #4865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@react-aria/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@react-aria/utils": "^3.18.0",
"@react-aria/visually-hidden": "^3.8.2",
"@react-stately/collections": "^3.9.0",
"@react-stately/flags": "3.0.0-alpha.0",
"@react-stately/table": "^3.10.0",
"@react-stately/virtualizer": "^3.6.0",
"@react-types/checkbox": "^3.4.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/table/src/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {mergeProps, useDescription, useId, useUpdateEffect} from '@react-aria/ut
import {Node} from '@react-types/shared';
import {RefObject, useMemo} from 'react';
import {TableKeyboardDelegate} from './TableKeyboardDelegate';
import {tableNestedRows} from '@react-stately/flags';
import {TableState, TreeGridState} from '@react-stately/table';
import {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';

Expand Down Expand Up @@ -70,7 +71,7 @@ export function useTable<T>(props: AriaTableProps<T>, state: TableState<T> | Tre
gridProps['aria-rowcount'] = state.collection.size + state.collection.headerRows.length;
}

if ('expandedKeys' in state) {
if (tableNestedRows() && 'expandedKeys' in state) {
gridProps.role = 'treegrid';
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/table/src/useTableHeaderRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import {DOMAttributes} from '@react-types/shared';
import {GridRowProps} from '@react-aria/grid';
import {RefObject} from 'react';
import {tableNestedRows} from '@react-stately/flags';
import {TableState} from '@react-stately/table';

export interface TableHeaderRowAria {
Expand All @@ -32,7 +33,7 @@ export function useTableHeaderRow<T>(props: GridRowProps<T>, state: TableState<T
role: 'row'
};

if (isVirtualized && !('expandedKeys' in state)) {
if (isVirtualized && !(tableNestedRows() && 'expandedKeys' in state)) {
rowProps['aria-rowindex'] = node.index + 1; // aria-rowindex is 1 based
}

Expand Down
5 changes: 3 additions & 2 deletions packages/@react-aria/table/src/useTableRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {GridRowAria, GridRowProps, useGridRow} from '@react-aria/grid';
import {HTMLAttributes, RefObject} from 'react';
import {mergeProps} from '@react-aria/utils';
import {TableCollection} from '@react-types/table';
import {tableNestedRows} from '@react-stately/flags';
import {TableState, TreeGridState} from '@react-stately/table';
import {useLocale} from '@react-aria/i18n';

Expand All @@ -42,14 +43,14 @@ export function useTableRow<T>(props: GridRowProps<T>, state: TableState<T> | Tr
let {rowProps, ...states} = useGridRow<T, TableCollection<T>, TableState<T>>(props, state, ref);
let {direction} = useLocale();

if (isVirtualized && !('expandedKeys' in state)) {
if (isVirtualized && !(tableNestedRows() && 'expandedKeys' in state)) {
rowProps['aria-rowindex'] = node.index + 1 + state.collection.headerRows.length; // aria-rowindex is 1 based
} else {
delete rowProps['aria-rowindex'];
}

let treeGridRowProps: HTMLAttributes<HTMLElement> = {};
if ('expandedKeys' in state) {
if (tableNestedRows() && 'expandedKeys' in state) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to just make a var for let isTreeGrid = tableNestedRows() && 'expandedKeys' in state; and use it here, but typescript wasn't smart enough to figure out that state would then be a TreeGridState only and complained about lines below

let treeNode = state.keyMap.get(node.key);
if (treeNode != null) {
let hasChildRows = treeNode.props?.UNSTABLE_childItems || treeNode.props?.children?.length > state.userColumnCount;
Expand Down