Skip to content

Commit fad66ba

Browse files
reidbarberLFDanLusnowystinger
authored
Add disabledBehavior to ListView docs (#3261)
* add disabledBehavior to ListView docs * address comments Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Robert Snow <[email protected]>
1 parent 5c59187 commit fad66ba

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

packages/@react-spectrum/list/docs/ListView.mdx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function PokemonList(props) {
258258
{id: 4, name: 'Pikachu'}
259259
];
260260

261-
let [selectedKeys, setSelectedKeys] = React.useState(new Set([2]));
261+
let [selectedKeys, setSelectedKeys] = React.useState(props.defaultSelectedKeys || new Set([2]));
262262

263263
return (
264264
<ListView items={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
293293

294294
### Disabled rows
295295

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.
297297

298298
```tsx example
299299
// Using the same list as above
300300
<PokemonList disabledKeys={[3]} aria-label="ListView with disabled rows" />
301301
```
302302

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+
<Flex wrap gap="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+
303325
### Highlight selection
304326

305327
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

Comments
 (0)