[Cdk drag-drop] Expose dragRef._pickupPositionInElement
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Öffne zunächst den verlinkten StackBlitz und lies die CDK Drag-and-drop DragRef API, insbesondere die Verwendung von _pickupPositionInElement mit cdkDragConstrainPosition. Verfolge, wie die cdkDrag-Direktive DragRef verfügbar macht, und entscheide, wo die Abholposition öffentlich zugänglich sein sollte. Erledigt ist die Aufgabe, wenn Verbraucher diese Position ohne einen any-Cast abrufen können und dabei das demonstrierte Einrastverhalten erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100