How to track the position of the Draggable component?

Đang mở
#385 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react
Lĩnh vực
frontend

Hướng nghiên cứu

Begin with the Draggable and DraggableCore APIs, focusing on the controlled position prop and the onStop callback shown in the issue. Determine whether the requested parent-state binding is an existing usage or documentation gap or requires a new API; completion should define the supported behavior and include tests if behavior changes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I want to track the (x, y) coordinates of the Draggable component.

I can't use the position prop like this, because then I cannot drag the component anymore:

const { posX, posY } = this.state;
return (
  ...
  <Draggable position={{x: posX, y: posY}}>
    <div style={{backgroundColor: "green", height: "30px", width: "30px"}}></div>
  </Draggable>
  ...
);

I've looked a bit at the DraggableCore API but I don't see how it could help me.

The only solution I found out yet is to set an onStop handler to the Draggable component like so:

handleOnStop(evt, data) {
  const { x, y } = data;
  this.setState({posX: x, posY: y});
}

Is there a simpler solution to bind directly the position coordinates in the parent state (posX, posY) to the props of the component?

Ngôn ngữ chính
JavaScript
Star
9.3k
Fork
1k
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
4

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react-grid-layout/react-draggable

Tất cả issue của react-grid-layout/react-draggable

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.