From 34e6fe0655ba4423b190e9de4eaf3dd6d1a3e3a5 Mon Sep 17 00:00:00 2001 From: tugcekucukoglu Date: Thu, 20 Feb 2025 12:22:23 +0300 Subject: [PATCH] Fixed #7246 - CascadeSelect breaks when modelValue doesn't exist in the options --- packages/primevue/src/cascadeselect/CascadeSelect.vue | 6 +++--- packages/primevue/src/cascadeselect/CascadeSelectSub.vue | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/primevue/src/cascadeselect/CascadeSelect.vue b/packages/primevue/src/cascadeselect/CascadeSelect.vue index 96107c77a..5e5126d8b 100644 --- a/packages/primevue/src/cascadeselect/CascadeSelect.vue +++ b/packages/primevue/src/cascadeselect/CascadeSelect.vue @@ -309,7 +309,7 @@ export default { const { index, key, level, parentKey, children } = processedOption; const grouped = isNotEmpty(children); - const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey && p.parentKey !== key); + const activeOptionPath = this.activeOptionPath ? this.activeOptionPath.filter((p) => p.parentKey !== parentKey && p.parentKey !== key) : []; this.focusedOptionInfo = { index, level, parentKey }; @@ -646,7 +646,7 @@ export default { return this.isValidOption(processedOption) && this.isSelected(processedOption); }, isSelected(processedOption) { - return this.activeOptionPath.some((p) => p.key === processedOption.key); + return this.activeOptionPath && this.activeOptionPath.some((p) => p.key === processedOption.key); }, findFirstOptionIndex() { return this.visibleOptions.findIndex((processedOption) => this.isValidOption(processedOption)); @@ -819,7 +819,7 @@ export default { return this.createProcessedOptions(this.options || []); }, visibleOptions() { - const processedOption = this.activeOptionPath.find((p) => p.key === this.focusedOptionInfo.parentKey); + const processedOption = this.activeOptionPath && this.activeOptionPath.find((p) => p.key === this.focusedOptionInfo.parentKey); return processedOption ? processedOption.children : this.processedOptions; }, diff --git a/packages/primevue/src/cascadeselect/CascadeSelectSub.vue b/packages/primevue/src/cascadeselect/CascadeSelectSub.vue index 873f1c687..f0365fe9e 100644 --- a/packages/primevue/src/cascadeselect/CascadeSelectSub.vue +++ b/packages/primevue/src/cascadeselect/CascadeSelectSub.vue @@ -131,7 +131,7 @@ export default { return equals(this.value, processedOption?.option); }, isOptionActive(processedOption) { - return this.activeOptionPath.some((path) => path.key === processedOption.key); + return this.activeOptionPath && this.activeOptionPath.some((path) => path.key === processedOption.key); }, isOptionFocused(processedOption) { return this.focusedOptionId === this.getOptionId(processedOption);