Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new feature - Picklist selectable #16045

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 76 additions & 39 deletions src/app/components/picklist/picklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,40 @@ import {
[attr.data-pc-group-section]="'list'"
>
<ng-template ngFor let-item [ngForOf]="source" [ngForTrackBy]="sourceTrackBy || trackBy" let-i="index" let-l="last">
<li
pRipple
cdkDrag
[id]="idSource + '_' + i"
[ngClass]="itemClass(item, idSource + '_' + i, selectedItemsSource)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(click)="onItemClick($event, item, selectedItemsSource, SOURCE_LIST, onSourceSelect, idSource + '_' + i)"
(mousedown)="onOptionMouseDown(i, SOURCE_LIST)"
(dblclick)="onSourceItemDblClick()"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, SOURCE_LIST)"
role="option"
[attr.data-pc-section]="'item'"
[attr.aria-selected]="isSelected(item, selectedItemsSource)"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
@if (selectable){
<li
pRipple
cdkDrag
[id]="idSource + '_' + i"
[ngClass]="itemClass(item, idSource + '_' + i, selectedItemsSource)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(click)="onItemClick($event, item, selectedItemsSource, SOURCE_LIST, onSourceSelect, idSource + '_' + i)"
(mousedown)="onOptionMouseDown(i, SOURCE_LIST)"
(dblclick)="onSourceItemDblClick()"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, SOURCE_LIST)"
role="option"
[attr.data-pc-section]="'item'"
[attr.aria-selected]="isSelected(item, selectedItemsSource)"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
}@else{
<li
cdkDrag
[id]="idSource + '_' + i"
[ngClass]="itemClass(item, idSource + '_' + i, selectedItemsSource)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, SOURCE_LIST)"
role="option"
[attr.data-pc-section]="'item'"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
}
</ng-template>
<ng-container *ngIf="isEmpty(SOURCE_LIST) && (emptyMessageSourceTemplate || emptyFilterMessageSourceTemplate)">
<li class="p-picklist-empty-message" *ngIf="!filterValueSource || !emptyFilterMessageSourceTemplate" [attr.data-pc-section]="'sourceEmptyMessage'">
Expand Down Expand Up @@ -271,24 +287,40 @@ import {
[attr.data-pc-group-section]="'list'"
>
<ng-template ngFor let-item [ngForOf]="target" [ngForTrackBy]="targetTrackBy || trackBy" let-i="index" let-l="last">
<li
pRipple
cdkDrag
[id]="idTarget + '_' + i"
[ngClass]="itemClass(item, idTarget + '_' + i, selectedItemsTarget)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(click)="onItemClick($event, item, selectedItemsTarget, TARGET_LIST, onTargetSelect, idTarget + '_' + i)"
(mousedown)="onOptionMouseDown(i, TARGET_LIST)"
(dblclick)="onTargetItemDblClick()"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, TARGET_LIST)"
role="option"
[attr.data-pc-section]="'item'"
[attr.aria-selected]="isSelected(item, selectedItemsTarget)"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
@if(selectable){
<li
pRipple
cdkDrag
[id]="idTarget + '_' + i"
[ngClass]="itemClass(item, idTarget + '_' + i, selectedItemsTarget)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(click)="onItemClick($event, item, selectedItemsTarget, TARGET_LIST, onTargetSelect, idTarget + '_' + i)"
(mousedown)="onOptionMouseDown(i, TARGET_LIST)"
(dblclick)="onTargetItemDblClick()"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, TARGET_LIST)"
role="option"
[attr.data-pc-section]="'item'"
[attr.aria-selected]="isSelected(item, selectedItemsTarget)"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
}@else{
<li
cdkDrag
[id]="idTarget + '_' + i"
[ngClass]="itemClass(item, idTarget + '_' + i, selectedItemsTarget)"
[cdkDragData]="item"
[cdkDragDisabled]="!dragdrop"
(touchend)="onItemTouchEnd()"
*ngIf="isItemVisible(item, TARGET_LIST)"
role="option"
[attr.data-pc-section]="'item'"
>
<ng-container *ngTemplateOutlet="itemTemplate; context: { $implicit: item, index: i }"></ng-container>
</li>
}
</ng-template>
<ng-container *ngIf="isEmpty(TARGET_LIST) && (emptyMessageTargetTemplate || emptyFilterMessageTargetTemplate)">
<li class="p-picklist-empty-message" *ngIf="!filterValueTarget || !emptyFilterMessageTargetTemplate" [attr.data-pc-section]="'targetEmptyMessage'">
Expand Down Expand Up @@ -474,6 +506,11 @@ export class PickList implements AfterViewChecked, AfterContentInit {
* @group Props
*/
@Input({ transform: booleanAttribute }) metaKeySelection: boolean = false;
/**
* Whether to enable item selection and button based movement or reordering.
* @group Props
*/
@Input({ transform: booleanAttribute }) selectable: boolean = true;
/**
* Whether to enable dragdrop based reordering.
* @group Props
Expand Down Expand Up @@ -918,7 +955,7 @@ export class PickList implements AfterViewChecked, AfterContentInit {
}

onItemClick(event: Event | any, item: any, selectedItems: any[], listType: number, callback: EventEmitter<any>, itemId?: string) {
if (this.disabled) {
if (!this.selectable || this.disabled) {
return;
}

Expand Down Expand Up @@ -1256,7 +1293,7 @@ export class PickList implements AfterViewChecked, AfterContentInit {
return {
'p-picklist-item': true,
'p-highlight': this.isSelected(item, selectedItems),
'p-focus': id === this.focusedOptionId,
'p-focus': this.selectable && id === this.focusedOptionId,
'p-disabled': this.disabled
};
}
Expand Down Expand Up @@ -1656,7 +1693,7 @@ export class PickList implements AfterViewChecked, AfterContentInit {
}

sourceMoveDisabled() {
if (this.disabled || !this.selectedItemsSource.length) {
if (!this.selectable || this.disabled || !this.selectedItemsSource.length) {
return true;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/app/showcase/doc/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -19091,6 +19091,14 @@
"default": "false",
"description": "Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically."
},
{
"name": "selectable",
"optional": false,
"readonly": false,
"type": "boolean",
"default": "true",
"description": "Whether to enable item selection and button based movement or reordering."
},
{
"name": "dragdrop",
"optional": false,
Expand Down Expand Up @@ -29523,4 +29531,4 @@
}
}
}
}
}
197 changes: 197 additions & 0 deletions src/app/showcase/doc/picklist/dragdropdoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { ChangeDetectorRef, Component } from '@angular/core';
import { Code } from '@domain/code';
import { Product } from '@domain/product';
import { ProductService } from '@service/productservice';

@Component({
selector: 'dragdrop-doc',
template: `
<app-docsectiontext>
<p>It is possible to toggle drag and drop functionality with the <i>dragdrop</i> property.</p>
</app-docsectiontext>
<div class="card">
<p-pickList
[source]="sourceProducts"
[target]="targetProducts"
sourceHeader="Available"
targetHeader="Selected"
[dragdrop]="false"
[responsive]="true"
[sourceStyle]="{ height: '30rem' }"
[targetStyle]="{ height: '30rem' }"
breakpoint="1400px"
>
<ng-template let-product pTemplate="item">
<div class="flex flex-wrap p-2 align-items-center gap-3">
<img class="w-4rem shadow-2 flex-shrink-0 border-round" src="https://primefaces.org/cdn/primeng/images/demo/product/{{ product.image }}" alt="{item.name}" />
<div class="flex-1 flex flex-column gap-2">
<span class="font-bold">{{ product.name }}</span>
<div class="flex align-items-center gap-2">
<i class="pi pi-tag text-sm"></i>
<span>{{ product.category }}</span>
</div>
</div>
<span class="font-bold text-900">{{ '$' + product.price }}</span>
</div>
</ng-template>
</p-pickList>
</div>
<app-code [code]="code" selector="picklist-dragdrop-demo" [extFiles]="extFiles"></app-code>
`
})
export class DragDropDoc {
sourceProducts!: Product[];

targetProducts!: Product[];

constructor(
private carService: ProductService,
private cdr: ChangeDetectorRef
) {}

ngOnInit() {
this.carService.getProductsSmall().then((products) => {
this.sourceProducts = products;
this.cdr.markForCheck();
});
this.targetProducts = [];
}

code: Code = {
basic: `<p-pickList
[source]="sourceProducts"
[target]="targetProducts"
sourceHeader="Available"
targetHeader="Selected"
[dragdrop]="false"
[responsive]="true"
[sourceStyle]="{ height: '30rem' }"
[targetStyle]="{ height: '30rem' }"
breakpoint="1400px">
<ng-template let-product pTemplate="item">
<div class="flex flex-wrap p-2 align-items-center gap-3">
<img
class="w-4rem shadow-2 flex-shrink-0 border-round"
src="https://primefaces.org/cdn/primeng/images/demo/product/{{ product.image }}"
alt="{item.name}" />
<div class="flex-1 flex flex-column gap-2">
<span class="font-bold">{{ product.name }}</span>
<div class="flex align-items-center gap-2">
<i class="pi pi-tag text-sm"></i>
<span>
{{ product.category }}
</span>
</div>
</div>
<span class="font-bold text-900">
{{ '$' + product.price }}
</span>
</div>
</ng-template>
</p-pickList>`,

html: `<div class="card">
<p-pickList
[source]="sourceProducts"
[target]="targetProducts"
sourceHeader="Available"
targetHeader="Selected"
[dragdrop]="false"
[responsive]="true"
[sourceStyle]="{ height: '30rem' }"
[targetStyle]="{ height: '30rem' }"
breakpoint="1400px">
<ng-template let-product pTemplate="item">
<div class="flex flex-wrap p-2 align-items-center gap-3">
<img
class="w-4rem shadow-2 flex-shrink-0 border-round"
src="https://primefaces.org/cdn/primeng/images/demo/product/{{ product.image }}"
alt="{item.name}" />
<div class="flex-1 flex flex-column gap-2">
<span class="font-bold">
{{ product.name }}
</span>
<div class="flex align-items-center gap-2">
<i class="pi pi-tag text-sm"></i>
<span>
{{ product.category }}
</span>
</div>
</div>
<span class="font-bold text-900">
{{ '$' + product.price }}
</span>
</div>
</ng-template>
</p-pickList>
</div>`,

typescript: `import { ChangeDetectorRef, Component } from '@angular/core';
import { Product } from '@domain/product';
import { ProductService } from '@service/productservice';
import { PickListModule } from 'primeng/picklist';

@Component({
selector: 'picklist-dragdrop-demo',
templateUrl: './picklist-dragdrop-demo.html',
standalone: true,
imports: [PickListModule],
providers: [ProductService]
})
export class PicklistDragdropDemo {
sourceProducts!: Product[];

targetProducts!: Product[];

constructor(
private carService: ProductService,
private cdr: ChangeDetectorRef
) {}

ngOnInit() {
this.carService.getProductsSmall().then(products => {
this.sourceProducts = products;
this.cdr.markForCheck();
});
this.targetProducts = [];
}
}`,

data: `
/* ProductService */
{
id: '1000',
code: 'f230fh0g3',
name: 'Bamboo Watch',
description: 'Product Description',
image: 'bamboo-watch.jpg',
price: 65,
category: 'Accessories',
quantity: 24,
inventoryStatus: 'INSTOCK',
rating: 5
},
...`,

service: ['ProductService']
};

extFiles = [
{
path: 'src/domain/product.ts',
content: `
export interface Product {
id?: string;
code?: string;
name?: string;
description?: string;
price?: number;
quantity?: number;
inventoryStatus?: string;
category?: string;
image?: string;
rating?: number;
}`
}
];
}
4 changes: 3 additions & 1 deletion src/app/showcase/doc/picklist/picklistdoc.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { AppCodeModule } from '@layout/doc/app.code.component';
import { AccessibilityDoc } from './accessibilitydoc';
import { BasicDoc } from './basicdoc';
import { FilterDoc } from './filterdoc';
import { DragDropDoc } from "./dragdropdoc";
import { SelectableDoc } from "./selectabledoc";
import { ImportDoc } from './importdoc';
import { StyleDoc } from './styledoc';
import { TemplatesDoc } from './templatesdoc';

@NgModule({
imports: [CommonModule, AppCodeModule, AppDocModule, PickListModule, RouterModule],
exports: [AppDocModule],
declarations: [ImportDoc, BasicDoc, FilterDoc, TemplatesDoc, StyleDoc, AccessibilityDoc]
declarations: [ImportDoc, BasicDoc, FilterDoc, TemplatesDoc, DragDropDoc, SelectableDoc, StyleDoc, AccessibilityDoc]
})
export class PicklistDocModule {}
Loading
Loading