angular / angular/components

[Cdk drag-drop] Expose dragRef._pickupPositionInElement

Abierto
#17,353 7 comentarios 7 reacciones 0 asignados Ver en GitHub
area: cdk/drag-drop feature P4
Lenguaje dominante
TypeScript
Estrellas
25k
Forks
6.8k
Merge medio
1 d 8 h
PR fusionados (30 d)
91

Descripción

Hello everyone,

I would like to ask for a small but nice to have feature in the CDK drag-and-drop module.

#### Feature Description

DragRef has a private member called `_pickupPositionInElement` that holds what it says : the { x, y } position where the user began a drag event. I would like to have this property public, or made accessible with a method instead of typing the following code that would break without any warning should the property change name : `(dragRef as any)._pickupPositionInElement`

#### Use Case

To create a custom control, I need to be able to drag items, and snap them to a "container". Dragged items are above the container, with a `position: absolute` styling. For that, I only use the `cdkDrag` directive, and the `cdkDragConstrainPosition` input.
In the method, I then search for the container-column to snap to, and return its position + the pickup position in element. If I don't add the pickup position, then the element does not snap as it should : I want the top left corner of the dragged element to be snapped to the top left corner of the column.

I created a stackblitz to show exactly what I am talking about : [here](https://stackblitz.com/edit/components-issue-wm4ugv)
Use the slider to toggle On/Off the use of `_pickupPositionInElement` and see that, when toggled off, the dragged element snaps based on where the drag has began (which is wrong for my use case). When toggled On, everything runs as it should. It is just that the ` as any` cast makes changes to the DragRef interface a potential invisible and undetectable breaking change for me…

Thanks for reading me and have a nice day!
Cheers.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Empieza abriendo el StackBlitz enlazado y leyendo la API de DragRef de CDK Drag-and-drop, especialmente el uso de _pickupPositionInElement con cdkDragConstrainPosition. Rastrea cómo la directiva cdkDrag expone DragRef y decide dónde debería poder accederse públicamente a la posición de recogida. Se considera completado cuando los consumidores puedan obtener esa posición sin un any cast y se conserve el comportamiento de ajuste mostrado.

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

Evaluación

Stack tecnológico
angular, typescript
Área
frontend
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.