angular / angular/components

feat(drag-drop): Make it easier to know when a CdkDropList is [no longer] hovered

Offen
#24,814 3 Kommentare 11 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: cdk/drag-drop feature P3
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

### Feature Description

Currently, the CDK/Drag-Drop module is very opinionated about what it allows the developer to do: have multiple lists/containers that a dragged item will snap to. For example, the two events on `CdkDropList` that tell you the current container to which a dragged item will snap to are `cdkDropListEntered` and `cdkDropListExited`.

However, because of the snapping functionality built into the module from the start, the `cdkDropListExited` event only fires when the item changes its linked container, not when the container HTMLElement is no longer hovered over (what we would expect from `dragEnter` and `dragLeave` from the native browser API).

While this makes the implementation and management of snapping containers much easier, it only complicates the implementation of non-snapping logic. Mostly because there is no *easy* way to know when a `cdkDropList` is no longer hovered.

My proposal is to either (or both)

**a)** Introduce two new events in `cdkDropList` that would mirror the native `dragEnter` and `dragLeave` events and would be triggered when a dragged item enter/leave the area occupied by the container's HTML element (the event mimicking `dragEnter` would not constitute a duplicate of the already existing `cdkDropListEntered` one because it is possible to drag the mouse cursor in and out of the container area multiple times while keeping the dragged item bound to it if no other container was hovered over during the operation).

**b)** Introduce a new type named `cdkHoverTarget` for example, which would act as a non-snapping hover target (and possibly not a container). It would expose the two events reflecting `dragEnter` and `dragLeave` and would be used to know when the user has its mouse cursor over a specific element during a drag operation.

### Use Case

One use of such a feature that I can think of would be in implementing a file manager: when dragging a file over a folder to move it into that folder, one would not expect the file preview to keep saying "move to " when the folder is no longer hovered over. This use case requires the developer to be able to know when a possible drop target is no longer hovered over, which is not trivial to achieve using the currently exposed events of the drag-drop module.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginnen Sie mit dem CDK/Drag-Drop-Modul und den vorhandenen CdkDropList-Ereignissen cdkDropListEntered und cdkDropListExited. Ermitteln Sie, ob native Enter-/Leave-Ereignisse oder ein separates Hover-Ziel ohne Einrasten hinzugefügt werden sollen, und betrachten Sie den Anwendungsfall eines Dateimanagers als Abschlusskriterium.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.