Skip to content

Commit

Permalink
Fixed #14698 - p-cascadeSelect | options: not change after new data i…
Browse files Browse the repository at this point in the history
…n array of options
  • Loading branch information
mehmetcetin01140 committed Mar 26, 2024
1 parent 7e17d57 commit 5afe84e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/app/components/cascadeselect/cascadeselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Output,
QueryList,
signal,
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation
Expand Down Expand Up @@ -295,7 +296,7 @@ export class CascadeSelectSub implements OnInit {
<div class="p-cascadeselect-items-wrapper" [attr.data-pc-section]="'wrapper'">
<p-cascadeSelectSub
class="p-cascadeselect-items"
[options]="processedOptions()"
[options]="processedOptions"
[selectId]="id"
[focusedOptionId]="focused ? focusedOptionId : undefined"
[activeOptionPath]="activeOptionPath()"
Expand Down Expand Up @@ -618,6 +619,8 @@ export class CascadeSelect implements OnInit, AfterContentInit {

modelValue = signal<any>(null);

processedOptions: string[] | string | undefined = [];

get containerClass() {
return {
'p-cascadeselect p-component p-inputwrapper': true,
Expand Down Expand Up @@ -679,11 +682,7 @@ export class CascadeSelect implements OnInit, AfterContentInit {
visibleOptions = computed(() => {
const processedOption = this.activeOptionPath().find((p) => p.key === this.focusedOptionInfo().parentKey);

return processedOption ? processedOption.children : this.processedOptions();
});

processedOptions = computed(() => {
return this.createProcessedOptions(this.options || []);
return processedOption ? processedOption.children : this.processedOptions;
});

label = computed(() => {
Expand All @@ -710,6 +709,13 @@ export class CascadeSelect implements OnInit, AfterContentInit {
return label;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.options) {
this.processedOptions = this.createProcessedOptions(this.options || []);
this.modelValue.set('');
}
}

hasSelectedOption() {
return ObjectUtils.isNotEmpty(this.modelValue());
}
Expand Down Expand Up @@ -1074,7 +1080,7 @@ export class CascadeSelect implements OnInit, AfterContentInit {
}

findOptionPathByValue(value, processedOptions?, level = 0) {
processedOptions = processedOptions || (level === 0 && this.processedOptions());
processedOptions = processedOptions || (level === 0 && this.processedOptions);

if (!processedOptions) return null;
if (ObjectUtils.isEmpty(value)) return [];
Expand Down

0 comments on commit 5afe84e

Please sign in to comment.