Skip to content

Commit

Permalink
🔧 multi-select unique by label
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-gn committed Feb 2, 2024
1 parent 8d84f2e commit 3886ccb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mprisma/components",
"version": "16.2.0",
"version": "16.2.1",
"repository": {
"type": "git",
"url": "https://github.com/gabriel-gn/prisma-components.git"
Expand Down
10 changes: 10 additions & 0 deletions src/components/inputs/multi-select/multi-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export class MultiSelectComponent implements OnInit, AfterViewInit, ControlValue
* Caso contrário, ao clicar sobre um item, remove ele da lista de selecionados
*/
@Input() showRemoveButton: boolean = false;
/**
* Caso a flag seja "true", filtra resultados selecionados apenas pela label.
*/
@Input() uniqueByLabel: boolean = false;
public _observableInputLoading: boolean = false;

public readonly myControl: UntypedFormControl;
Expand Down Expand Up @@ -221,6 +225,12 @@ export class MultiSelectComponent implements OnInit, AfterViewInit, ControlValue
}

public isOptionSelected(option: (MultiSelectOption|any)): boolean {
if (this.uniqueByLabel) {
if (isMultiSelectOption(option)) {
return !!this.selectedOptions.find(sOptions => sOptions.label === option.label);
}
}

if (isMultiSelectOption(option)) {
return !!this.selectedOptions.find(sOptions => _.isEqual(sOptions, option));
} else {
Expand Down

0 comments on commit 3886ccb

Please sign in to comment.