Browse Source

demo: fix table drag demo click event not working (#43291)

pull/43303/head
daisy 1 year ago
committed by GitHub
parent
commit
ab036297b3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      components/table/demo/drag-sorting.tsx

15
components/table/demo/drag-sorting.tsx

@ -1,9 +1,9 @@
import type { DragEndEvent } from '@dnd-kit/core';
import { DndContext } from '@dnd-kit/core';
import { DndContext, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
import {
arrayMove,
SortableContext,
arrayMove,
useSortable,
verticalListSortingStrategy,
} from '@dnd-kit/sortable';
@ -77,6 +77,15 @@ const App: React.FC = () => {
},
]);
const sensors = useSensors(
useSensor(PointerSensor, {
activationConstraint: {
// https://docs.dndkit.com/api-documentation/sensors/pointer#activation-constraints
distance: 1,
},
}),
);
const onDragEnd = ({ active, over }: DragEndEvent) => {
if (active.id !== over?.id) {
setDataSource((prev) => {
@ -88,7 +97,7 @@ const App: React.FC = () => {
};
return (
<DndContext modifiers={[restrictToVerticalAxis]} onDragEnd={onDragEnd}>
<DndContext sensors={sensors} modifiers={[restrictToVerticalAxis]} onDragEnd={onDragEnd}>
<SortableContext
// rowKey array
items={dataSource.map((i) => i.key)}

Loading…
Cancel
Save