You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add disabledBehavior to ListView docs
* address comments
Co-authored-by: Daniel Lu <[email protected]>
Co-authored-by: Robert Snow <[email protected]>
Copy file name to clipboardExpand all lines: packages/@react-spectrum/list/docs/ListView.mdx
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -258,7 +258,7 @@ function PokemonList(props) {
258
258
{id: 4, name: 'Pikachu'}
259
259
];
260
260
261
-
let [selectedKeys, setSelectedKeys] =React.useState(newSet([2]));
261
+
let [selectedKeys, setSelectedKeys] =React.useState(props.defaultSelectedKeys||newSet([2]));
262
262
263
263
return (
264
264
<ListViewitems={rows}maxWidth="size-6000"aria-label="ListView with controlled selection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}{...props}>
@@ -293,13 +293,35 @@ In this mode, if a single row is selected and the user presses it, it will not b
293
293
294
294
### Disabled rows
295
295
296
-
You can disable specific rows by providing an array of keys to ListView via the `disabledKeys` prop. This will prevent rows from being selectable, as shown in the example below.
296
+
You can disable specific rows by providing an array of keys to ListView via the `disabledKeys` prop. This will disable all interactions on disabled rows, unless the `disabledBehavior` prop is used to change this behavior.
297
297
298
298
```tsx example
299
299
// Using the same list as above
300
300
<PokemonListdisabledKeys={[3]}aria-label="ListView with disabled rows" />
301
301
```
302
302
303
+
If you set the `disabledBehavior` prop to `selection`, interactions such as focus, dragging, or actions can still be performed on disabled rows.
304
+
```tsx example
305
+
<Flexwrapgap="size-300">
306
+
<PokemonList
307
+
disabledKeys={[3]}
308
+
defaultSelectedKeys={[]}
309
+
disabledBehavior="all"
310
+
aria-label="ListView with all interaction disabled for disabled rows"
311
+
width="size-2400"
312
+
onAction={key=>alert(`Opening item ${key}...`)}
313
+
/>
314
+
<PokemonList
315
+
disabledKeys={[3]}
316
+
defaultSelectedKeys={[]}
317
+
disabledBehavior="selection"
318
+
aria-label="ListView with selection disabled for disabled rows"
319
+
width="size-2400"
320
+
onAction={key=>alert(`Opening item ${key}...`)}
321
+
/>
322
+
</Flex>
323
+
```
324
+
303
325
### Highlight selection
304
326
305
327
By default, ListView uses the checkbox selection style, which includes a checkbox in each row for selection. When the selectionStyle prop is set to `"highlight"`, the checkboxes are hidden,
0 commit comments