Skip to content

Sortable with removable items and with layout animations #684

Answered by clauderic
joseDaKing asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @joseDaKing,

There are two pieces required to have @dnd-kit manage layout animations for you, as can be seen in the removable items example.

First, you must pass a custom measuring config to <DndContext> to tell @dnd-kit to always measure droppable containers, even when not dragging. By default, @dnd-kit only measures items while dragging.

import {MeasuringStrategy} from '@dnd-kit/core';

const measuringConfig = {
  droppable: {
    strategy: MeasuringStrategy.Always,
  },
};

<DndContext measuring={measuringConfig} />

Next, you need to tell useSortable to animate layout changes when not sorting:

import {defaultAnimateLayoutChanges} from '@dnd-kit/sortable';

function customAnimateLay…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@joseDaKing
Comment options

Answer selected by clauderic
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants