How to track the position of the Draggable component?

Abierto
#385 2 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript, react
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?

Lenguaje dominante
JavaScript
Estrellas
9.3k
Forks
1k
Merge medio
3 d 8 h
PR fusionados (30 d)
4

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de react-grid-layout/react-draggable

Todos los issues de react-grid-layout/react-draggable

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.