Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
fix: use appendStatusClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed May 21, 2018
1 parent 9da0c40 commit 125f28f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/lib/droppable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@ export class DroppableDirective
handleDragover(e: Event) {
e.preventDefault();
e.stopPropagation();
this.element.nativeElement.classList.add(this.dragOverClass);
if (this.appendStatusClasses) {
this.element.nativeElement.classList.add(this.dragOverClass);
}
}

@HostListener('dragleave', ['$event'])
handleDragleave(e: Event) {
e.preventDefault();
e.stopPropagation();
this.element.nativeElement.classList.remove(this.dragOverClass);
if (this.appendStatusClasses) {
this.element.nativeElement.classList.remove(this.dragOverClass);
}
}

@HostListener('drop', ['$event'])
handleDrop(e: Event) {
e.preventDefault();
e.stopPropagation();
this.element.nativeElement.classList.remove(this.dragOverClass);
if (this.appendStatusClasses) {
this.element.nativeElement.classList.remove(this.dragOverClass);
}
this.onDroppableElementChange(e);
}

Expand Down
18 changes: 17 additions & 1 deletion src/lib/droppable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { DroppableDirective } from './droppable.directive';
template: `<div droppable #droppable="droppable"
(filesDropped)="handleFilesDropped($event)"
[acceptsMultipleFiles]="acceptsMultipleFiles"
></div>
[appendStatusClasses]="appendStatusClasses"
></div>
`,
})
export class TestComponent {
@ViewChild('droppable') droppable: DroppableDirective;
acceptsMultipleFiles = true;
appendStatusClasses = true;
files: File[] = [];
handleFilesDropped(files: File[]) {
this.files = files;
Expand Down Expand Up @@ -83,5 +85,19 @@ describe('Droppable', () => {
tc.droppable.handleDragleave(fakeEvent);
expect(nc.querySelector('div').classList.contains(tc.droppable.dragOverClass)).toBe(false);
}));
it('should not add the dragOverClass to the element when appendStatusClasses is false', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
const tc: TestComponent = fixture.debugElement.componentInstance;
tc.appendStatusClasses = false;
fixture.detectChanges();
const nc = fixture.debugElement.nativeElement;
tc.droppable.handleDragover(fakeEvent);
expect(nc.querySelector('div').classList.contains(tc.droppable.dragOverClass)).toBe(false);
expect(fakeEvent.preventDefault).toHaveBeenCalled();
expect(fakeEvent.stopPropagation).toHaveBeenCalled();
tc.droppable.handleDragleave(fakeEvent);
expect(nc.querySelector('div').classList.contains(tc.droppable.dragOverClass)).toBe(false);
}));
});
});

0 comments on commit 125f28f

Please sign in to comment.