Skip to content

Commit c09fd51

Browse files
author
Brian Ryu
committed
Allow keyboard-accessible sorting
1 parent 0512151 commit c09fd51

File tree

5 files changed

+414
-58
lines changed

5 files changed

+414
-58
lines changed

src/.stories/index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function getItems(count, height) {
3030
const Handle = SortableHandle(() => <div className={style.handle} />);
3131

3232
const Item = SortableElement((props) => {
33+
const tabIndex = props.tabbable ? 0 : -1;
34+
3335
return (
3436
<div
3537
className={props.className}
@@ -39,7 +41,7 @@ const Item = SortableElement((props) => {
3941
}}
4042
>
4143
{props.shouldUseDragHandle && <Handle />}
42-
<div className={style.wrapper}>
44+
<div className={style.wrapper} tabIndex={tabIndex}>
4345
<span>Item</span> {props.value}
4446
</div>
4547
</div>
@@ -52,6 +54,7 @@ const SortableList = SortableContainer(
5254
<div className={className}>
5355
{items.map(({value, height}, index) => (
5456
<Item
57+
tabbable
5558
key={`item-${value}`}
5659
className={itemClass}
5760
index={index}
@@ -86,11 +89,13 @@ class SortableListWithCustomContainer extends React.Component {
8689
}
8790

8891
const Category = SortableElement((props) => {
92+
const tabIndex = props.tabbable ? 0 : -1;
93+
8994
return (
9095
<div className={style.category}>
9196
<div className={style.categoryHeader}>
9297
<Handle />
93-
<span>Category {props.value}</span>
98+
<span tabIndex={tabIndex}>Category {props.value}</span>
9499
</div>
95100
<ListWrapper
96101
component={SortableList}
@@ -178,6 +183,7 @@ const SortableVirtualList = SortableContainer(
178183
const {value, height} = items[index];
179184
return (
180185
<Item
186+
tabbable
181187
key={value}
182188
index={index}
183189
className={itemClass}
@@ -209,6 +215,7 @@ class VirtualizedListWrapper extends Component {
209215
const {value, height} = items[index];
210216
return (
211217
<Item
218+
tabbable
212219
key={value}
213220
index={index}
214221
className={itemClass}
@@ -289,6 +296,7 @@ const SortableInfiniteList = SortableContainer(
289296
>
290297
{items.map(({value, height}, index) => (
291298
<Item
299+
tabbable
292300
key={`item-${index}`}
293301
className={itemClass}
294302
index={index}
@@ -307,6 +315,7 @@ const ShrinkingSortableList = SortableContainer(
307315
<div className={className}>
308316
{items.map(({value, height}, index) => (
309317
<Item
318+
tabbable
310319
key={`item-${value}`}
311320
className={itemClass}
312321
index={index}
@@ -325,7 +334,7 @@ const NestedSortableList = SortableContainer(
325334
return (
326335
<div className={className}>
327336
{items.map((value, index) => (
328-
<Category key={`category-${value}`} index={index} value={value} />
337+
<Category tabbable key={`category-${value}`} index={index} value={value} />
329338
))}
330339
</div>
331340
);

src/Manager.js

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export default class Manager {
2828
);
2929
}
3030

31+
getActiveKeyLift() {
32+
return this.refs[this.activeKeyLift.collection].find(
33+
// eslint-disable-next-line eqeqeq
34+
({node}) => node.sortableInfo.index == this.activeKeyLift.index,
35+
);
36+
}
37+
3138
getIndex(collection, ref) {
3239
return this.refs[collection].indexOf(ref);
3340
}

0 commit comments

Comments
 (0)