Skip to content

Commit dbf221d

Browse files
committed
feat: add KeyboardSensor for keyboard-accessible reordering
1 parent f4b2d50 commit dbf221d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/components/DraggableList/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {DragEndEvent} from '@dnd-kit/core';
2-
import {closestCenter, DndContext, PointerSensor, useSensor} from '@dnd-kit/core';
2+
import {closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';
33
import {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';
4-
import {arrayMove, SortableContext, verticalListSortingStrategy} from '@dnd-kit/sortable';
4+
import {arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';
55
import React, {Fragment} from 'react';
66
// eslint-disable-next-line no-restricted-imports
77
import type {ScrollView as RNScrollView} from 'react-native';
@@ -69,13 +69,16 @@ function DraggableList<T>({
6969
);
7070
});
7171

72-
const sensors = [
72+
const sensors = useSensors(
7373
useSensor(PointerSensor, {
7474
activationConstraint: {
7575
distance: minimumActivationDistance,
7676
},
7777
}),
78-
];
78+
useSensor(KeyboardSensor, {
79+
coordinateGetter: sortableKeyboardCoordinates,
80+
}),
81+
);
7982

8083
const Container = disableScroll ? Fragment : ScrollView;
8184

0 commit comments

Comments
 (0)