mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-01 15:37:16 +00:00
Fix: add disable to the drag-drop list component (#13880)
This commit is contained in:
+2
@@ -3,6 +3,7 @@
|
||||
<div class="d-flex flex-wrap flex-row gap-2 w-100 mh-1" style="min-height: 1em;"
|
||||
cdkDropList #selectedList="cdkDropList"
|
||||
cdkDropListOrientation="mixed"
|
||||
[cdkDropListDisabled]="disabled"
|
||||
(cdkDropListDropped)="drop($event)"
|
||||
[cdkDropListConnectedTo]="[unselectedList]">
|
||||
@for (item of selectedItems; track item.id) {
|
||||
@@ -17,6 +18,7 @@
|
||||
<div class="d-flex flex-wrap flex-row gap-2 w-100" style="min-height: 1em;"
|
||||
cdkDropList #unselectedList="cdkDropList"
|
||||
cdkDropListOrientation="mixed"
|
||||
[cdkDropListDisabled]="disabled"
|
||||
(cdkDropListDropped)="drop($event)"
|
||||
[cdkDropListConnectedTo]="[selectedList]">
|
||||
@for (item of unselectedItems; track item.id) {
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
.badge {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.cdk-drop-list-disabled {
|
||||
cursor: not-allowed !important;
|
||||
|
||||
* {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -98,4 +98,29 @@ describe('DragDropSelectComponent', () => {
|
||||
{ id: '3', name: 'Item 3' },
|
||||
])
|
||||
})
|
||||
|
||||
it('should disable drag and drop when the control is disabled', () => {
|
||||
component.items = [
|
||||
{ id: '1', name: 'Item 1' },
|
||||
{ id: '2', name: 'Item 2' },
|
||||
]
|
||||
component.writeValue(['1', '2'])
|
||||
component.setDisabledState(true)
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(component.selectedList.disabled).toBe(true)
|
||||
expect(component.unselectedList.disabled).toBe(true)
|
||||
|
||||
component.drop({
|
||||
previousContainer: component.selectedList,
|
||||
container: component.selectedList,
|
||||
previousIndex: 0,
|
||||
currentIndex: 1,
|
||||
} as any)
|
||||
|
||||
expect(component.selectedItems).toEqual([
|
||||
{ id: '1', name: 'Item 1' },
|
||||
{ id: '2', name: 'Item 2' },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -46,6 +46,8 @@ export class DragDropSelectComponent extends AbstractInputComponent<string[]> {
|
||||
}
|
||||
|
||||
public drop(event: CdkDragDrop<string[]>) {
|
||||
if (this.disabled) return
|
||||
|
||||
if (
|
||||
event.previousContainer === event.container &&
|
||||
event.container === this.selectedList
|
||||
|
||||
Reference in New Issue
Block a user