Skip to content

Commit f6ce7ac

Browse files
On row action docs 2 (#2694)
* Updated onRowAction docs for useTable * review comment * Update packages/@react-aria/table/docs/useTable.mdx Co-authored-by: Danni <[email protected]>
1 parent 5bf5440 commit f6ce7ac

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/@react-aria/table/docs/useTable.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ import {useRef} from 'react';
135135
import {useFocusRing} from '@react-aria/focus';
136136

137137
function Table(props) {
138-
let {selectionMode, selectionBehavior, onAction} = props;
138+
let {selectionMode, selectionBehavior} = props;
139139
let state = useTableState({
140140
...props,
141141
showSelectionCheckboxes: selectionMode === 'multiple' && selectionBehavior !== 'replace'
@@ -160,7 +160,7 @@ function Table(props) {
160160
</TableRowGroup>
161161
<TableRowGroup type="tbody">
162162
{[...collection.body.childNodes].map(row => (
163-
<TableRow key={row.key} item={row} state={state} onAction={onAction}>
163+
<TableRow key={row.key} item={row} state={state}>
164164
{[...row.childNodes].map(cell =>
165165
cell.props.isSelectionCell
166166
? <TableCheckboxCell key={cell.key} cell={cell} state={state} />
@@ -259,19 +259,18 @@ Now that we've covered the table header, let's move on to the body. We'll use
259259
the <TypeLink links={docs.links} type={docs.exports.useTableRow} /> hook to render each row in the table.
260260
Table rows can be focused and navigated to using the keyboard via the arrow keys. In addition, table rows
261261
can optionally support selection via mouse, touch, or keyboard. Clicking, tapping, or pressing the <kbd>Space</kbd>
262-
key anywhere in the row selects it. Row actions are also supported via the provided `onAction` prop. See [below](#row-and-cell-actions) for details.
262+
key anywhere in the row selects it. Row actions are also supported, see [below](#row-and-cell-actions) for details.
263263

264264
We'll use the <TypeLink links={selectionDocs.links} type={selectionDocs.exports.SelectionManager} /> object exposed
265265
by the `state` to determine if a row is selected, and render a pink background if so. We'll also use the <TypeLink links={focusDocs.links} type={focusDocs.exports.useFocusRing} />
266266
hook to render a focus ring when the user navigates to the row with the keyboard.
267267

268268
```tsx example export=true render=false
269-
function TableRow({item, children, state, onAction}) {
269+
function TableRow({item, children, state}) {
270270
let ref = useRef();
271271
let isSelected = state.selectionManager.isSelected(item.key);
272272
let {rowProps, isPressed} = useTableRow({
273-
node: item,
274-
onAction: onAction && (() => onAction(item.key))
273+
node: item
275274
}, state, ref);
276275
let {isFocusVisible, focusProps} = useFocusRing();
277276

@@ -611,10 +610,11 @@ When the `selectionBehavior` prop is set to `"replace"`, clicking a row with the
611610

612611
`useTable` may be used in use cases where users can perform actions on rows or cells, such as navigating into items to open them or get more details. In the default `"toggle"` selection behavior, it is recommended to use a link in the first column for navigation.
613612

614-
In the `"replace"` selection behavior, the `onAction` prop can be used to enable row and cell actions, which differ depending on the interaction method. When provided to `useTableRow` or `useTableCell`, double clicking with a mouse or pressing the <kbd>Enter</kbd> key triggers `onAction`, while single click and the <kbd>Space</kbd> key are reserved for selection. On touch devices, `onAction` becomes the primary tap interaction, and a long press enters into selection mode, which temporarily swaps the selection behavior to `"toggle"` to perform selection (you may wish to display checkboxes when this happens). Deselecting all items exits selection mode and reverts the selection behavior back to `"replace"`. Double clicking matches the behavior of desktop platforms like macOS and Windows, and a separate selection mode matches mobile platforms like iOS and Android.
613+
In the `"replace"` selection behavior, the `onRowAction` and `onCellAction` prop can be used to enable row and cell actions, which differ depending on the interaction method. When provided to `useTableState`, double clicking with a mouse or pressing the <kbd>Enter</kbd> key triggers the action, while single click and the <kbd>Space</kbd> key are reserved for selection. On touch devices, the action becomes the primary tap interaction, and a long press enters into selection mode, which temporarily swaps the selection behavior to `"toggle"` to perform selection (you may wish to display checkboxes when this happens). Deselecting all items exits selection mode and reverts the selection behavior back to `"replace"`. Double clicking matches the behavior of desktop platforms like macOS and Windows, and a separate selection mode matches mobile platforms like iOS and Android.
614+
615615

616616
```tsx example
617-
<PokemonTable selectionMode="multiple" selectionBehavior="replace" onAction={key => alert(`Opening item ${key}...`)} />
617+
<PokemonTable selectionMode="multiple" selectionBehavior="replace" onRowAction={key => alert(`Opening item ${key}...`)} />
618618
```
619619

620620
### Sorting

0 commit comments

Comments
 (0)