@@ -26,8 +26,8 @@ function getItems(count, height) {
26
26
} ) ;
27
27
}
28
28
29
- const Handle = SortableHandle ( ( ) => (
30
- < div className = { style . handle } >
29
+ const Handle = SortableHandle ( ( { tabIndex } ) => (
30
+ < div className = { style . handle } tabIndex = { tabIndex } >
31
31
< svg viewBox = "0 0 50 50" >
32
32
< path
33
33
d = "M 0 7.5 L 0 12.5 L 50 12.5 L 50 7.5 L 0 7.5 z M 0 22.5 L 0 27.5 L 50 27.5 L 50 22.5 L 0 22.5 z M 0 37.5 L 0 42.5 L 50 42.5 L 50 37.5 L 0 37.5 z"
@@ -37,21 +37,34 @@ const Handle = SortableHandle(() => (
37
37
</ div >
38
38
) ) ;
39
39
40
- const Item = SortableElement ( ( props ) => {
40
+ const Item = SortableElement ( ( {
41
+ tabbable,
42
+ className,
43
+ isDisabled,
44
+ height,
45
+ style : propStyle ,
46
+ shouldUseDragHandle,
47
+ value
48
+ } ) => {
49
+ const isTabbable = tabbable && ! isDisabled ;
50
+ const bodyTabIndex = isTabbable && ! shouldUseDragHandle ? 0 : - 1 ;
51
+ const handleTabIndex = isTabbable && shouldUseDragHandle ? 0 : - 1 ;
52
+
41
53
return (
42
54
< div
43
55
className = { classNames (
44
- props . className ,
45
- props . isDisabled && style . disabled ,
56
+ className ,
57
+ isDisabled && style . disabled ,
46
58
) }
47
59
style = { {
48
- height : props . height ,
49
- ...props . style ,
60
+ height,
61
+ ...propStyle ,
50
62
} }
63
+ tabIndex = { bodyTabIndex }
51
64
>
52
- { props . shouldUseDragHandle && < Handle /> }
65
+ { shouldUseDragHandle && < Handle tabIndex = { handleTabIndex } /> }
53
66
< div className = { style . wrapper } >
54
- < span > Item</ span > { props . value }
67
+ < span > Item</ span > { value }
55
68
</ div >
56
69
</ div >
57
70
) ;
@@ -66,6 +79,7 @@ const SortableList = SortableContainer(
66
79
67
80
return (
68
81
< Item
82
+ tabbable
69
83
key = { `item-${ value } ` }
70
84
disabled = { disabled }
71
85
isDisabled = { disabled }
@@ -103,11 +117,13 @@ class SortableListWithCustomContainer extends React.Component {
103
117
}
104
118
105
119
const Category = SortableElement ( ( props ) => {
120
+ const tabIndex = props . tabbable ? 0 : - 1 ;
121
+
106
122
return (
107
123
< div className = { style . category } >
108
124
< div className = { style . categoryHeader } >
109
125
< Handle />
110
- < span > Category { props . value } </ span >
126
+ < span tabIndex = { tabIndex } > Category { props . value } </ span >
111
127
</ div >
112
128
< ListWrapper
113
129
component = { SortableList }
@@ -212,6 +228,7 @@ const SortableReactWindow = (Component) =>
212
228
213
229
return (
214
230
< Item
231
+ tabbable
215
232
key = { value }
216
233
index = { index }
217
234
className = { itemClass }
@@ -236,6 +253,7 @@ const SortableVirtualList = SortableContainer(
236
253
const { value, height} = items [ index ] ;
237
254
return (
238
255
< Item
256
+ tabbable
239
257
key = { value }
240
258
index = { index }
241
259
className = { itemClass }
@@ -267,6 +285,7 @@ class VirtualizedListWrapper extends Component {
267
285
const { value, height} = items [ index ] ;
268
286
return (
269
287
< Item
288
+ tabbable
270
289
key = { value }
271
290
index = { index }
272
291
className = { itemClass }
@@ -344,9 +363,13 @@ const SortableInfiniteList = SortableContainer(
344
363
className = { className }
345
364
containerHeight = { 600 }
346
365
elementHeight = { items . map ( ( { height} ) => height ) }
366
+ // for react-infinite, a larger preload is better for keyboard sorting
367
+ preloadBatchSize = { Infinite . containerHeightScaleFactor ( 2 ) }
368
+ preloadAdditionalHeight = { Infinite . containerHeightScaleFactor ( 2 ) }
347
369
>
348
370
{ items . map ( ( { value, height} , index ) => (
349
371
< Item
372
+ tabbable
350
373
key = { `item-${ index } ` }
351
374
className = { itemClass }
352
375
index = { index }
@@ -365,6 +388,7 @@ const ShrinkingSortableList = SortableContainer(
365
388
< div className = { className } >
366
389
{ items . map ( ( { value, height} , index ) => (
367
390
< Item
391
+ tabbable
368
392
key = { `item-${ value } ` }
369
393
className = { itemClass }
370
394
index = { index }
@@ -383,7 +407,7 @@ const NestedSortableList = SortableContainer(
383
407
return (
384
408
< div className = { className } >
385
409
{ items . map ( ( value , index ) => (
386
- < Category key = { `category-${ value } ` } index = { index } value = { value } />
410
+ < Category tabbable key = { `category-${ value } ` } index = { index } value = { value } />
387
411
) ) }
388
412
</ div >
389
413
) ;
0 commit comments