Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@dnd-kit/utilities

clauderic7.5mMIT3.2.2TypeScript support: included

Internal utilities to bee shared between @dnd-kit packages

readme

@dnd-kit/utilities

Stable release

Internal utilities to bee shared between @dnd-kit packages.

changelog

@dnd-kit/utilities

3.2.2

Patch Changes

  • #1239 f342d5e Thanks @petdud! - Fix: getOwnerDocument should get correct document for SVG Elements

3.2.1

Patch Changes

3.2.0

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.

3.1.0

Minor Changes

  • #518 6310227 Thanks @clauderic! - Major internal refactor of measuring and collision detection.

    Summary of changes

    Previously, all collision detection algorithms were relative to the top and left points of the document. While this approach worked in most situations, it broke down in a number of different use-cases, such as fixed position droppable containers and trying to drag between containers that had different scroll positions.

    This new approach changes the frame of comparison to be relative to the viewport. This is a major breaking change, and will need to be released under a new major version bump.

    Breaking changes:

    • By default, @dnd-kit now ignores only the transforms applied to the draggable / droppable node itself, but considers all the transforms applied to its ancestors. This should provide the right balance of flexibility for most consumers.
      • Transforms applied to the droppable and draggable nodes are ignored by default, because the recommended approach for moving items on the screen is to use the transform property, which can interfere with the calculation of collisions.
      • Consumers can choose an alternate approach that does consider transforms for specific use-cases if needed by configuring the measuring prop of <DndContext>. Refer to the <Switch> example.
    • Reduced the number of concepts related to measuring from ViewRect, LayoutRect to just a single concept of ClientRect.
      • The ClientRect interface no longer holds the offsetTop and offsetLeft properties. For most use-cases, you can replace offsetTop with top and offsetLeft with left.
      • Replaced the following exports from the @dnd-kit/core package with getClientRect:
        • getBoundingClientRect
        • getViewRect
        • getLayoutRect
        • getViewportLayoutRect
    • Removed translatedRect from the SensorContext interface. Replace usage with collisionRect.
    • Removed activeNodeClientRect on the DndContext interface. Replace with activeNodeRect.
  • 528c67e Thanks @clauderic! - Introduced the useLatestValue hook, which returns a ref that holds the latest value of a given argument. Optionally, the second argument can be used to customize the dependencies passed to the effect.

Patch Changes

  • #561 02edd26 Thanks @clauderic! - - The useNodeRef hook's onChange argument now receives both the current node and the previous node that were attached to the ref.
    • The onChange argument is only called if the previous node differs from the current node

3.0.2

Patch Changes

  • #532 dfa8d69 Thanks @Nauss! - fix: isWindow has been updated to support checking wether an element is a window object in Electron applications.

3.0.1

Patch Changes

  • #509 1c6369e Thanks @clauderic! - Helpers have been updated to support rendering in foreign window contexts (via ReactDOM.render or ReactDOM.createPortal).

    For example, checking if an element is an instance of an HTMLElement is normally done like so:

    if (element instanceof HTMLElement)

    However, when rendering in a different window, this can return false even if the element is indeed an HTMLElement, because this code is equivalent to:

    if (element instanceof window.HTMLElement)

    And in this case, the window of the element is different from the main execution context window, because we are rendering via a portal into another window.

    This can be solved by finding the local window of the element:

    const elementWindow = element.ownerDocument.defaultView;
    
    if (element instanceof elementWindow.HTMLElement)

3.0.0

Major Changes

Minor Changes

  • #334 13be602 Thanks @trentmwillis! - Move Coordinates interface along with getEventCoordinates, isMouseEvent and isTouchEvent helpers to @dnd-kit/utilities

Patch Changes

  • #437 0e628bc Thanks @chestozo! - Added PointerEvent support to the getEventCoordinates method. This fixes testing the PointerSensor with Cypress (#436)

2.0.0

Major Changes

  • a9d92cf #174 Thanks @clauderic! - Distributed assets now only target modern browsers. Browserlist config:

    defaults
    last 2 version
    not IE 11
    not dead

    If you need to support older browsers, include the appropriate polyfills in your project's build process.

1.0.3

Patch Changes

1.0.2

Patch Changes

1.0.1

Patch Changes

1.0.0

Major Changes

0.1.0

Minor Changes