daybrush / moveable

Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
https://daybrush.com/moveable/
MIT License
10.08k stars 618 forks source link

Feature request: allow for separate drag handle #217

Closed isteven closed 4 years ago

isteven commented 4 years ago

Environments

Description

As per title, would be great if the drag handle can be a separate element, like:

<div class="panel"> // this can accept other things like resize, rotate etc.. 
    <div class="header">HEADER</div> // ... but this is the only element which can accept drag
    <div class="content">CONTENT</div>
</div>

Visually, something like this image

I'm quite sure a lot of people will appreciate this, as I believe many of us use this library to build some sort of multi panel / tab / window application on the web.

Thank you!

iprasadg commented 4 years ago

Yes seperate drag handle will be very helpful and user friendly. #148

mellinger commented 4 years ago

It's not too crazy to implement like this:

  moveable.on("dragStart", (event) => {
    if (!event.inputEvent.srcElement.classList.contains("handle")) {
      event.stop();
    }
  });
isteven commented 4 years ago

It's not too crazy to implement like this:

  moveable.on("dragStart", (event) => {
    if (!event.inputEvent.srcElement.classList.contains("handle")) {
      event.stop();
    }
  });

@mellinger how do I implement this for the React version of the library? By default the dragStart event doesn't pass event object.

(And yes I'm a React noob)

daybrush commented 4 years ago

@isteven @mellinger @iprasadg

moveable's new version is released.

add dragTarget, props.

like this:

moveable.dragTarget = document.querySelector(".otherTarget");

https://daybrush.com/moveable/release/latest/doc/Moveable.html#dragTarget

isteven commented 4 years ago

Hi @daybrush,

Thank you! I will try in the next few days.

To use it in the React version, is it like this?

render() {
    return (
        <Moveable
            target={document.querySelector(".target")}
            dragTarget={document.querySelector(".otherTarget")}
            ...
            ...
        />
    )
}
daybrush commented 4 years ago

@isteven yes.

isteven commented 4 years ago

Hi @daybrush ,

Thanks for 0.20.1 update, I am currently trying it as per your advice.

However, I encountered this error:

image

The context, if they can help:

I was merely following your documentation: image