Skip to content

Releases: clauderic/dnd-kit

@dnd-kit/[email protected]

14 Jun 17:52
3979c12
Compare
Choose a tag to compare

Patch Changes

@dnd-kit/[email protected]

14 Jun 17:21
eec27f3
Compare
Choose a tag to compare

Patch Changes

@dnd-kit/[email protected]

30 May 01:03
8fbbfd7
Compare
Choose a tag to compare

Patch Changes

  • #776 3978c43 Thanks @clauderic! - The ARIA live region element used for screen reader announcements is now positioned using position: fixed instead of position: absolute. As of @dnd-kit/core^6.0.0, the live region element is no longer portaled by default into the document.body. This change was introduced in order to fix issues with portaled live regions. However, this change can introduce visual regressions when using absolutely positioned elements, since the live region element is constrained to the stacking and position context of its closest positioned ancestor. Using fixed position ensures the element does not introduce visual regressions.

@dnd-kit/[email protected]

29 May 15:51
90cb663
Compare
Choose a tag to compare

Patch Changes

  • #772 e97cb1f Thanks @clauderic! - The ARIA live region element used for screen reader announcements is now positioned using position: fixed instead of position: absolute. As of @dnd-kit/core^6.0.0, the live region element is no longer portaled by default into the document.body. This change was introduced in order to fix issues with portaled live regions. However, this change can introduce visual regressions when using absolutely positioned elements, since the live region element is constrained to the stacking and position context of its closest positioned ancestor. Using fixed position ensures the element does not introduce visual regressions.

@dnd-kit/[email protected]

27 May 20:06
78538a5
Compare
Choose a tag to compare

Patch Changes

  • #769 8e3599f Thanks @clauderic! - Fixed an issue with the containerNodeRect that is exposed to modifiers having stale properties (top, left, etc.) when its scrollable ancestors were scrolled.

  • #769 53cb962 Thanks @clauderic! - Fixed a regression with scrollable ancestors detection.

    The scrollable ancestors should be determined by the active node or the over node exclusively. The draggingNode variable shouldn't be used to detect scrollable ancestors since it can be the drag overlay node, and the drag overlay node doesn't have any scrollable ancestors because it is a fixed position element.

@dnd-kit/[email protected]

21 May 01:59
336bfc3
Compare
Choose a tag to compare

Minor Changes

  • #748 59ca82b Thanks @clauderic! - Introduced the findFirstFocusableNode utility function that returns the first focusable node within a given HTMLElement, or the element itself if it is focusable.

  • #733 035021a Thanks @clauderic! - Introduced the useEvent hook based on implementation breakdown in the RFC. In the future, this hook will be used as a polyfill if the native React hook is unavailble.

@dnd-kit/[email protected]

21 May 01:59
336bfc3
Compare
Choose a tag to compare

Major Changes

  • #755 33e6dd2 Thanks @clauderic! - The UniqueIdentifier type has been updated to now accept either string or number identifiers. As a result, the id property of useDraggable, useDroppable and useSortable and the items prop of <SortableContext> now all accept either string or number identifiers.

    Migration steps

    For consumers that are using TypeScript, import the UniqueIdentifier type to have strongly typed local state:

    + import type {UniqueIdentifier} from '@dnd-kit/core';
    
    function MyComponent() {
    -  const [items, setItems] = useState(['A', 'B', 'C']);
    +  const [items, setItems] = useState<UniqueIdentifier>(['A', 'B', 'C']);
    }

    Alternatively, consumers can cast or convert the id property to a string when reading the id property of interfaces such as Active, Over, DroppableContainer and DraggableNode.

    The draggableNodes object has also been converted to a map. Consumers that were reading from the draggableNodes property that is available on the public context of <DndContext> should follow these migration steps:

    - draggableNodes[someId];
    + draggableNodes.get(someId);
  • #660 30bbd12 Thanks @clauderic! - Changes to the default sortableKeyboardCoordinates KeyboardSensor coordinate getter.

    Better handling of variable sizes

    The default sortableKeyboardCoordinates function now has better handling of lists that have items of variable sizes. We recommend that consumers re-order lists onDragOver instead of onDragEnd when sorting lists of variable sizes via the keyboard for optimal compatibility.

    Better handling of overlapping droppables

    The default sortableKeyboardCoordinates function that is exported from the @dnd-kit/sortable package has been updated to better handle cases where the collision rectangle is overlapping droppable rectangles. For example, for down arrow key, the default function had logic that would only consider collisions against droppables that were below the bottom edge of the collision rect. This was problematic when the collision rect was overlapping droppable rects, because it meant that it's bottom edge was below the top edge of the droppable, and that resulted in that droppable being skipped.

    - collisionRect.bottom > droppableRect.top
    + collisionRect.top > droppableRect.top

    This change should be backwards compatible for most consumers, but may introduce regressions in some use-cases, especially for consumers that may have copied the multiple containers examples. There is now a custom sortable keyboard coordinate getter optimized for multiple containers that you can refer to.

Minor Changes

  • #748 59ca82b Thanks @clauderic! - Automatic focus management and activator node refs.

    Introducing activator node refs

    Introducing the concept of activator node refs for useDraggable and useSortable. This allows @dnd-kit to handle common use-cases such as restoring focus on the activator node after dragging via the keyboard or only allowing the activator node to instantiate the keyboard sensor.

    Consumers of useDraggable and useSortable may now optionally set the activator node ref on the element that receives listeners:

    import {useDraggable} from '@dnd-kit/core';
    
    function Draggable(props) {
      const {
        listeners,
        setNodeRef,
    +   setActivatorNodeRef,
      } = useDraggable({id: props.id});
    
      return (
        <div ref={setNodeRef}>
          Draggable element
          <button
            {...listeners}
    +       ref={setActivatorNodeRef}
          >
            :: Drag Handle
          </button>
        </div>
      )
    }

    It's common for the activator element (the element that receives the sensor listeners) to differ from the draggable node. When this happens, @dnd-kit has no reliable way to get a reference to the activator node after dragging ends, as the original event.target that instantiated the sensor may no longer be mounted in the DOM or associated with the draggable node that was previously active.

    Automatically restoring focus

    Focus management is now automatically handled by @dnd-kit. When the activator event is a Keyboard event, @dnd-kit will now attempt to automatically restore focus back to the first focusable node of the activator node or draggable node.

    If no activator node is specified via the setActivatorNodeRef setter function of useDraggble and useSortable, @dnd-kit will automatically restore focus on the first focusable node of the draggable node set via the setNodeRef setter function of useDraggable and useSortable.

    If you were previously managing focus manually and would like to opt-out of automatic focus management, use the newly introduced restoreFocus property of the accessibility prop of <DndContext>:

    <DndContext
      accessibility={{
    +   restoreFocus: false
      }}
  • #672 10f6836 Thanks @clauderic! - SortableContext now always requests measuring of droppable containers when its items prop changes, regardless of whether or not dragging is in progress. Measuring will occur if the measuring configuration allows for it.

  • #754 224201a Thanks @clauderic! - The <SortableContext> component now optionally accepts a disabled prop to globally disable useSortable hooks rendered within it.

    The disabled prop accepts either a boolean or an object with the following shape:

    interface Disabled {
      draggable?: boolean;
      droppable?: boolean;
    }

    The useSortable hook has now been updated to also optionally accept the disabled configuration object to conditionally disable the useDraggable and/or useDroppable hooks used internally.

    Like the strategy prop, the disabled prop defined on the useSortable hook takes precedence over the disabled prop defined on the parent <SortableContext>.

Patch Changes

Read more

@dnd-kit/[email protected]

21 May 01:59
336bfc3
Compare
Choose a tag to compare

@dnd-kit/[email protected]

21 May 14:41
3986031
Compare
Choose a tag to compare

Patch Changes

  • #759 e5b9d38 Thanks @clauderic! - Fixed a regression with the default drop animation of <DragOverlay> for consumers using React 18.

@dnd-kit/[email protected]

21 May 01:59
336bfc3
Compare
Choose a tag to compare

Major Changes

  • #746 4173087 Thanks @clauderic! - Accessibility related changes.

    Regrouping accessibility-related props

    Accessibility-related props have been regrouped under the accessibility prop of <DndContext>:

    <DndContext
    - announcements={customAnnouncements}
    - screenReaderInstructions={customScreenReaderInstructions}
    + accessibility={{
    +  announcements: customAnnouncements,
    +  screenReaderInstructions: customScreenReaderInstructions,
    + }}

    This is a breaking change that will allow easier addition of new accessibility-related features without overloading the props namespace of <DndContext>.

    Arguments object for announcements

    The arguments passed to announcement callbacks have changed. They now receive an object that contains the active and over properties that match the signature of those passed to the DragEvent handlers (onDragStart, onDragMove, etc.). This change allows consumers to read the data property of the active and over node to customize the announcements based on the data.

    Example migration steps:

    export const announcements: Announcements = {
    -  onDragStart(id) {
    +  onDragStart({active}) {
    -    return `Picked up draggable item ${id}.`;
    +    return `Picked up draggable item ${active.id}.`;
      },
    -  onDragOver(id, overId) {
    +  onDragOver({active, over}) {
    -    if (overId) {
    +    if (over) {
    -      return `Draggable item ${id} was moved over droppable area ${overId}.`;
    +      return `Draggable item ${active.id} was moved over droppable area ${over.id}.`;
        }
    
    -    return `Draggable item ${id} is no longer over a droppable area.`;
    +    return `Draggable item ${active.id} is no longer over a droppable area.`;
      },
    };

    Accessibility-related DOM nodes are no longer portaled by default

    The DOM nodes for the screen reader instructions and announcements are no longer portaled into the document.body element by default.

    This change is motivated by the fact that screen readers do not always announce ARIA live regions that are rendered on the document.body. Common examples of this include when rendering a <DndContext> within a <dialog> element or an element that has role="dialog", only ARIA live regions rendered within the dialog will be announced.

    Consumers can now opt to render announcements in the portal container of their choice using the container property of the accessibility prop:

    <DndContext
    + accessibility={{
    +  container: document.body,
    + }}
  • #733 035021a Thanks @clauderic! - The <DragOverlay> component's drop animation has been refactored, which fixes a number of bugs with the existing implementation and introduces new functionality.

    What's new?

    Scrolling the draggable node into view if needed

    The drop animation now ensures that the the draggable node that we are animating to is in the viewport before performing the drop animation and scrolls it into view if needed.

    Changes to the dropAnimation prop

    The dropAnimation prop of <DragOverlay> now accepts either a configuration object or a custom drop animation function.

    The configuration object adheres to the following shape:

    interface DropAnimationOptions {
      duration?: number;
      easing?: string;
      keyframes?: DropAnimationKeyframeResolver;
      sideEffects?: DropAnimationSideEffects;
    }

    The default drop animation options are:

    const defaultDropAnimationConfiguration: DropAnimationOptions = {
      duration: 250,
      easing: 'ease',
      keyframes: defaultDropAnimationKeyframes,
      sideEffects: defaultDropAnimationSideEffects({
        styles: {
          active: {
            opacity: '0',
          },
        },
      }),
    };

    The keyframes option allows consumers to override the keyframes of the drop animation. For example, here is how you would add a fade out transition to the drop animation using keyframes:

    import {CSS} from '@dnd-kit/utilities';
    
    const customDropAnimation = {
      keyframes({transform}) {
        return [
          {opacity: 1, transform: CSS.Transform.toString(transform.initial)},
          {opacity: 0, transform: CSS.Transform.toString(transform.final)},
        ];
      },
    };

    The dragSourceOpacity option has been deprecated in favour of letting consumers define arbitrary side effects that should run before the animation starts. Side effects may return a cleanup function that should run when the drop animation has completed.

    type CleanupFunction = () => void;
    
    export type DropAnimationSideEffects = (
      parameters: DropAnimationSideEffectsParameters
    ) => CleanupFunction | void;

    Drop animation side effects are a powerful abstraction that provide a lot of flexibility. The defaultDropAnimationSideEffects function is exported by @dnd-kit/core and aims to facilitate the types of side-effects we anticipate most consumers will want to use out of the box:

    interface DefaultDropAnimationSideEffectsOptions {
      // Apply a className on the active draggable or drag overlay node during the drop animation
      className?: {
        active?: string;
        dragOverlay?: string;
      };
      // Apply temporary styles to the active draggable node or drag overlay during the drop animation
      styles?: {
        active?: Styles;
        dragOverlay?: Styles;
      };
    }

    For advanced side-effects, consumers may define a custom sideEffects function that may optionally return a cleanup function that will be executed when the drop animation completes:

    const customDropAnimation = {
      sideEffects({active}) {
        active.node.classList.add('dropAnimationInProgress');
        active.node.animate([{opacity: 0}, {opacity: 1}], {
          easing: 'ease-in',
          duration: 250,
        });
    
        return () => {
          // Clean up when the drop animation is complete
          active.node.classList.remove('dropAnimationInProgress');
        };
      },
    };

    For even more advanced use-cases, consumers may also provide a function to the dropAnimation prop, which adheres to the following shape:

    interface DropAnimationFunctionArguments {
      active: {
        id: UniqueIdentifier;
        data: DataRef;
        node: HTMLElement;
        rect: ClientRect;
      };
      draggableNodes: DraggableNodes;
      dragOverlay: {
        node: HTMLElement;
        rect: ClientRect;
      };
      droppableContainers: DroppableContainers;
      measuringConfiguration: DeepRequired<MeasuringConfiguration>;
      transform: Transform;
    }
    
    type DropAnimationFunction = (
      args: DropAnimationFunctionArguments
    ) => Promise<void> | void;

    Bug fixes

    • The <DragOverlay> now respects the measuringConfiguration specified for the dragOverlay and draggable properties when measuring the rects to animate to and from.
    • The <DragOverlay> component now supports rendering children while performing the drop animation. Previously, the drag overlay would be in a broken state when trying to pick up an item while a drop animation was in progress.

    Migration steps

    For consumers that were relying on the dragSourceOpacity property in their dropAnimation configuration:

    + import {defaultDropAnimationSideEffects} from '@dnd-kit/core';
    
    const dropAnimation = {
    - dragSourceOpacity: 0.5,
    + sideEffects: defaultDropAnimationSideEffects({
    +   styles : {
    +     active: {
    +       opacity: '0.5',
    +     },
    +   },
    +  ),
    };
  • #745 5f3c700 Thanks @clauderic! - The keyboard sensor now keeps track of the initial coordinates of the collision rect to provide a translate delta when move events are dispatched.

    This is a breaking change that may affect consumers that had created custom keyboard coordinate getters.

    Previously the keyboard sensor would measure the initial rect of the active node and store its top and left properties as its initial coordinates it would then compare all subsequent move coordinates to calculate the delta.

    This approach suffered from the following issues:

    • It didn't respect the measuring configuration defined on the <DndContext> for the draggable node
    • Some consumers re-render the active node after dragging begins, which would lead to stale measurements
    • An error had to be thrown if there was no active node during the activation phase of the keyboard sensor. This shouldn't be a concern of the keyboard sensor.
    • The currentCoordinates passed to the coordinate getter were often stale and not an accurate representation of the current position of the collision rect, which can be affected by a number of different variables, such as modifiers.
  • #755 33e6dd2 Thanks @clauderic! - The UniqueIdentifier type has been updated to now accept either string or number identifiers. As a result, the id property of useDraggable, useDroppable an...

Read more