Accept function as child or pass raw position

Open
#414 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, react
Domain
frontend

Research direction

No files, tests, or entry points are named. Begin by locating how react-draggable renders its child and passes position, style, and mouse/touch handlers; clarify whether the intended API is a function child, raw position data, or both, then add coverage for the chosen behavior.

Written by the indexing model from the issue text.

Description

It would be convenient if react-draggable accepted a function as a child. Instead of requiring the child be a <div /> or <svg /> and passing the appropriate props, a function would with called with the position. For example:

<Draggable>
{
  /* additional arguments could be onTouchStart, onMouseMove, etc. */
  (position, ...args) => {
    <div
      style={{
        transform=`translateX(${position.x}px) translateY(${position.y}px)`
      }}
      {...args}
    >
      Drag me!
    </div>
  }
}
</Draggable>

This would allow greater flexibility in how the child component can be structured.

Otherwise it is easy enough to pass along onMouse/onTouch events and the style prop - but if the child component needs to consume the position for reasons other than style, it must regex the values out of the style.transform string. A compromise could be always pass the raw position object as well.

My apologies if this has been brought up in the past; I couldn't find any other mention.

Dominant language
JavaScript
Stars
9.3k
Forks
1k
Avg merge
3d 8h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react-grid-layout/react-draggable

All issues in react-grid-layout/react-draggable

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.