marcojakob / dart-dnd

Drag and Drop for Dart web apps with mouse and touch support.
https://code.makery.ch/library/dart-drag-and-drop/
MIT License
135 stars 86 forks source link

Pls. add a way to set something like an "invalid-zone" css class #7

Closed MikeMitterer closed 9 years ago

MikeMitterer commented 9 years ago

First of all - Thanks for your package! It would be cool if you could add a way to add an indicator for an invalid (not allowed) Drop-Zone.

I tried it with my own Acceptor and it's possible to do something like this:

    @override
    bool accepts(final html.Element draggableElement,final int draggableId,final html.Element dropzoneElement) {

        final bool isValid = _isDragZoneValid();
        if(!isValid) {
            dropzoneElement.classes.add("dnd-invalid");
        } else {
            dropzoneElement.classes.remove("dnd-invalid");
        }
        return isValid;
    }

The problem with this approach is that dnd-invalid is set but never unset because an invalid drop-zone never gets onDragLeave... - so no way to remove the dnd-invalid class.

marcojakob commented 9 years ago

That's a valid point. I will have a look at that.

marcojakob commented 9 years ago

The fix adds a css class (dnd-invalid by default) to dropzones when a not-accepted draggable is dragged over.

See it in action: http://marcojakob.github.io/dart-dnd/custom-acceptor/