Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
3bc6f78
poking around to make Rows process nested rows
LFDanLu May 31, 2023
0bf43fd
cleanup
LFDanLu May 31, 2023
4609379
progress
LFDanLu Jun 1, 2023
22dde54
got nested rows rendering
LFDanLu Jun 2, 2023
9fb0a5f
fixing naming and adding way to track rows that have nested rows
LFDanLu Jun 2, 2023
d57f877
fixing expandable row detection and debugging weird TableLayout issue
LFDanLu Jun 2, 2023
529125e
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Jun 5, 2023
7c26625
renaming from treeble to TreeGrid
LFDanLu Jun 5, 2023
4db5b4c
fix cell values and weird crash with dynamic treeble with subset of k…
LFDanLu Jun 5, 2023
092b43c
update left/right keyboard navigation logic
LFDanLu Jun 6, 2023
c630325
updating up/down keyboard navigation logic
LFDanLu Jun 6, 2023
29cd760
fixing typeahead and using this.getChildNodes whereever possible
LFDanLu Jun 6, 2023
2af16aa
cleanup and fix getText
LFDanLu Jun 6, 2023
c44b194
fixing index and column assignment to node
LFDanLu Jun 6, 2023
b4a9cf1
debugging persisted keys
LFDanLu Jun 6, 2023
c8aa238
adding basic story to check controlled expanded keys
LFDanLu Jun 7, 2023
c9ca507
musings when trying to fix persisted key case
LFDanLu Jun 7, 2023
b5c62d8
enforcing user places cells before nested rows
LFDanLu Jun 8, 2023
a6f090e
making GridNode index track position with respect to parent and addin…
LFDanLu Jun 8, 2023
56d31cb
fixing persisted keys by adding index for headerrows and columns
LFDanLu Jun 8, 2023
6671f88
create Table wrapper element to conditionally render Table or TreeGri…
LFDanLu Jun 8, 2023
1a00526
get rid of extra story
LFDanLu Jun 8, 2023
fdcf68b
update keyboard delegate to use node.indexOfType
LFDanLu Jun 8, 2023
5ccc400
adding tree grid aria
LFDanLu Jun 9, 2023
e423431
fix crash on collapse
LFDanLu Jun 9, 2023
6ef96de
fixes from screen reader testing
LFDanLu Jun 12, 2023
bb30a78
setting up tests, debugging why they dont run
LFDanLu Jun 12, 2023
7d5a3a6
add feature flag getter for tests for now
LFDanLu Jun 13, 2023
73ec246
fixing row border styling and adding more tests
LFDanLu Jun 14, 2023
c0f5ca8
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Jun 14, 2023
6535a2c
TableView expandable rows: rendering + interactions (#4663)
reidbarber Jun 20, 2023
8c6aafe
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Jun 23, 2023
cddc437
fix shared context for base tableview and treegrid tableview
LFDanLu Jun 23, 2023
4ee99c5
fixing lint for build
LFDanLu Jun 23, 2023
191f96a
adding more stories
LFDanLu Jun 23, 2023
e73aca3
adding more row selection test
LFDanLu Jun 24, 2023
98f34eb
make NVDA/Talkback not announce the chevron label when the cell is fo…
LFDanLu Jun 26, 2023
c3cf0ae
add chevron rotation transition and increase hit target
LFDanLu Jun 26, 2023
ca0ed13
add chromatic stories
reidbarber Jun 27, 2023
465c471
adding tests for loading state, onAction, and highlight selection
LFDanLu Jun 29, 2023
b509f40
adding persisted key and remaining keyboard nav tests
LFDanLu Jun 30, 2023
4b84adb
add expand/collapse tests
LFDanLu Jun 30, 2023
bf8adff
(WIP) Simplify TreeGridCollection by building the keymap inside state…
LFDanLu Jun 30, 2023
dfcdea1
Refactoring TableView wrapper strategy
LFDanLu Jun 30, 2023
8c20b77
renaming tableview files
LFDanLu Jun 30, 2023
1ec0deb
getting rid of extraneous shouldShowCheckbox
LFDanLu Jun 30, 2023
3d1eecc
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Jun 30, 2023
0f98137
fixing tests for react-17
LFDanLu Jul 1, 2023
1e66b0f
add nested table examples to docs
reidbarber Jul 11, 2023
d5fc9b3
update example data to be nested
reidbarber Jul 11, 2023
43250b3
document feature flag
reidbarber Jul 11, 2023
6ab1d16
cleaning up todos
LFDanLu Jul 11, 2023
0e958ce
fix types
reidbarber Jul 11, 2023
9537eab
Merge branch 'main' into expandable_rows_collection_update
LFDanLu Jul 11, 2023
eb5524e
updating per review
LFDanLu Jul 11, 2023
b38acc3
adding alpha to types
LFDanLu Jul 11, 2023
72e680c
update heights
reidbarber Jul 11, 2023
bb2bae2
Add message for feature flag pointing to docs
LFDanLu Jul 11, 2023
9bd8f9f
Merge branch 'expandable_rows_collection_update' of github.com:adobe/…
LFDanLu Jul 11, 2023
0feac04
review comments
LFDanLu Jul 12, 2023
78f270c
fix typo
reidbarber Jul 14, 2023
ced41eb
Remove zoom transition effect from TableView (#4771)
LFDanLu Jul 17, 2023
7fc7fef
Adding UNSTABLE to expandable rows state hook and prop
LFDanLu Jul 18, 2023
dfae99b
addressing review comments
LFDanLu Jul 18, 2023
d2324b8
moving expand/collapse chevron label to intl files
LFDanLu Jul 18, 2023
db3348f
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Jul 18, 2023
da0c81c
Merge branch 'expandable_rows_collection_update' of github.com:adobe/…
LFDanLu Jul 18, 2023
a56dcb9
update prop naming
LFDanLu Jul 18, 2023
f7252e0
updating copy for feature flag
LFDanLu Jul 18, 2023
c517cec
addressing review comments (prop rename and stuff)
LFDanLu Jul 20, 2023
777de01
hide expandable table props from spectrum docs
LFDanLu Jul 20, 2023
c9e9d76
removing column node assigment to treegrid node cell
LFDanLu Jul 20, 2023
de56a4f
expanding type and fixing tests to get rid of .onlys
LFDanLu Jul 20, 2023
be833bb
Merge branch 'expandable_rows_collection_update' of github.com:adobe/…
LFDanLu Jul 20, 2023
1d3a324
updating docs copy for new prop names and exposing props in props tables
LFDanLu Jul 20, 2023
02515a9
fix tests in 17
LFDanLu Jul 20, 2023
0349928
Merge branch 'expandable_rows_collection_update' of github.com:adobe/…
LFDanLu Jul 21, 2023
decca29
Merge branch 'main' of github.com:adobe/react-spectrum into expandabl…
LFDanLu Aug 4, 2023
e595600
remove extraneous strings
LFDanLu Aug 4, 2023
fb499c1
Merge branch 'main' into expandable-rows-docs
reidbarber Aug 28, 2023
df683b8
Merge branch 'main' into expandable-rows-docs
dannify Nov 15, 2023
2c4e8d0
fix key type
reidbarber Nov 16, 2023
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
117 changes: 115 additions & 2 deletions packages/@react-spectrum/table/docs/TableView.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ keywords: [table, grid]
```

## Content
TableView is a complex [collection component](../react-stately/collections.html) that is built up from many child elements including columns, rows, and cells. Columns are defined within a TableHeader element and rows are defined within a TableBody element. Rows contain Cell elements that correspond to each column. Cells can contain any element, allowing you to have focusable children within the TableView.
TableView is a complex [collection component](../react-stately/collections.html) that is built up from many child elements including columns, rows, and cells. Columns are defined within a TableHeader element and rows are defined within a TableBody element. Rows contain `Cell` elements that correspond to each column. Cells can contain any element, allowing you to have focusable children within the TableView.

Basic usage of TableView, seen in the example above, shows the use of a static collection where the contents of the TableView is hard coded. Dynamic collections, as shown below, can be used when the options come from an external data source such as an API, or update over time. Providing the data in this way allows TableView to automatically cache the rendering of each item, which dramatically improves performance.

Expand Down Expand Up @@ -367,7 +367,7 @@ function AsyncTable() {
## Selection

By default, TableView doesn't allow row selection but this can be enabled using the `selectionMode` prop.
Use `defaultSelectedKeys` to provide a default set of selected rows. Note that the value of the selected keys must match the `key` prop of the Row.
Use `defaultSelectedKeys` to provide a default set of selected rows. Note that the value of the selected keys must match the `key` prop of the `Row`.

The example below enables multiple selection mode, and uses `defaultSelectedKeys` to select the rows with keys "2" and "4".

Expand Down Expand Up @@ -1622,6 +1622,119 @@ function CustomDragPreviewExample() {
<CustomDragPreviewExample />
```

## Expandable Rows <VersionBadge version="alpha" style={{marginLeft: 4, verticalAlign: 'bottom'}} />

By default, TableView doesn't allow expandable rows, but this can be enabled by toggling the feature flag via `enableTableNestedRows` in your app and then providing the `UNSTABLE_allowsExpandableRows` prop to
your TableView.

```tsx example
import {enableTableNestedRows} from '@react-stately/flags';
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add where in your app this should go? eg the root vs the file that expandable rows is used? or anywhere? does it matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update this section with some clarification. Here is the entire explanation:

This approach is the easiest because the flags can be accessed from anywhere. However, one downside is that flags are enabled for all instances of a component across the whole app, not for one specific table for example. We could do that with context, but then the flags would need to be wired to more places that aren't allowed to access classes (e.g. classes, non-hook functions, etc.). The flags also need to be set before anything is rendered in the app or things may break unexpectedly, so libraries like quarry should not be enabling flags, they should be enabled in apps. Like any other package, there must be only one copy installed or things will also not work.

From #4617

Copy link
Member Author

Choose a reason for hiding this comment

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

So you'll want to do this once, likely at the root of your app since it will affect all instances and should be done before rendering the table.


enableTableNestedRows();
```
<br />

Use `UNSTABLE_defaultExpandedKeys` to provide a default set of expanded rows. Note that the value of the expanded keys must match the `key` prop of the `Row` and that an
expanded child row will only be visible if its parent row key is also included within the expanded key set.

An expandable row can be statically defined by including one or more `Rows` as children. Note that all child `Rows` must be placed after the last `Cell` within the parent `Row`.

The example below enables expandable rows, and uses `UNSTABLE_defaultExpandedKeys` to expand rows with keys "1" and "2".

```tsx example
<TableView aria-label="Example table with expandable rows" UNSTABLE_allowsExpandableRows UNSTABLE_defaultExpandedKeys={['1', '2']} height="size-4600">
<TableHeader>
<Column>Name</Column>
<Column>Capital</Column>
<Column align="end">Population</Column>
</TableHeader>
<TableBody>
<Row key="1">
<Cell>United States</Cell>
<Cell>Washington, D.C.</Cell>
<Cell>331.9 million</Cell>
<Row key="2">
<Cell>California</Cell>
<Cell>Sacramento</Cell>
<Cell>39.24 million</Cell>
<Row key="3">
<Cell>San Jose</Cell>
<Cell>-</Cell>
<Cell>983.4 thousand</Cell>
</Row>
</Row>
<Row key="4">
<Cell>Texas</Cell>
<Cell>Austin</Cell>
<Cell>29.53 million</Cell>
<Row key="5">
<Cell>Dallas</Cell>
<Cell>-</Cell>
<Cell>1.28 million</Cell>
</Row>
</Row>
</Row>
</TableBody>
</TableView>
```

### Controlled expandable rows

To programmatically control row expansion, use the `UNSTABLE_expandedKeys` prop paired with the `UNSTABLE_onExpandedChange` callback. The `key` prop from the expanded rows will
be passed into the callback when the row's expand button is pressed, allowing you to update state accordingly.

Here is how you would control expanded rows for the above example. Additionally, note how expandable rows can be dynamically defined by providing the child rows data to the
parent `Row`'s `UNSTABLE_childItems` prop.

```tsx example
import type {Key} from '@react-types/shared';

interface ColumnDefinition {
name: string,
key: string,
}

function TableExample(props) {
let columns: ColumnDefinition[] = [
{name: 'Name', key: 'name'},
{name: 'Capital', key: 'capital'},
{name: 'Population', key: 'population'}
];

let nestedRows = [
{key: '1', name: 'United States', capital: 'Washington, D.C.', population: '331.9 million', childRows: [
{key: '2', name: 'California', capital: 'Sacramento', population: '39.24 million', childRows: [
{key: '3', name: 'San Jose', capital: '-', population: '983.4 thousand'}
]},
{key: '4', name: 'Texas', capital: 'Austin', population: '29.53 million', childRows: [
{key: '5', name: 'Dallas', capital: '-', population: '1.28 million'}
]}
]}
];

let [expandedKeys, setExpandedKeys] = React.useState<'all' | Iterable<Key>>('all');

return (
<TableView aria-label="Example table with controlled expandable rows" UNSTABLE_allowsExpandableRows UNSTABLE_expandedKeys={expandedKeys} UNSTABLE_onExpandedChange={setExpandedKeys} height="size-4600">
<TableHeader columns={columns}>
{column => (
<Column align={column.key === 'population' ? 'end' : 'start'}>
{column.name}
</Column>
)}
</TableHeader>
<TableBody items={nestedRows}>
{item => (
<Row key={item.key} UNSTABLE_childItems={item.childRows}>
{(key) => <Cell>{item[key]}</Cell>}
</Row>
)}
</TableBody>
</TableView>
);
}
```

## Props

### TableView props
Expand Down
4 changes: 0 additions & 4 deletions packages/@react-spectrum/table/src/TableViewWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,24 @@ export interface SpectrumTableProps<T> extends TableProps<T>, SpectrumSelectionP
/**
* Whether the TableView should support expandable rows. Requires the feature flag to be enabled first, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
* @version alpha
* @private
*/
UNSTABLE_allowsExpandableRows?: boolean,
/**
* The currently expanded keys in the collection (controlled). Requires the feature flag to be
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
* @version alpha
* @private
*/
UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,
/**
* The initial expanded keys in the collection (uncontrolled). Requires the feature flag to be
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
* @version alpha
* @private
*/
UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,
/**
* Handler that is called when items are expanded or collapsed. Requires the feature flag to be
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
* @version alpha
* @private
*/
UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any
}
Expand Down
1 change: 0 additions & 1 deletion packages/@react-types/table/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export interface RowProps<T> extends LinkDOMProps {
* A list of child item objects used when dynamically rendering row children. Requires the feature flag to be
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
* @version alpha
* @private
*/
UNSTABLE_childItems?: Iterable<T>,
// TODO: update when async loading is supported for expandable rows
Expand Down