From d09d992e7175b0faf132ac5624661bf845d3b3ad Mon Sep 17 00:00:00 2001 From: tugcekucukoglu Date: Mon, 7 Oct 2024 11:59:27 +0300 Subject: [PATCH] Fixed #6533 - CascadeSelect: move move/enter behavior changes --- .../src/cascadeselect/CascadeSelect.vue | 26 +++++++++++++------ .../src/cascadeselect/CascadeSelectSub.vue | 22 ++++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/packages/primevue/src/cascadeselect/CascadeSelect.vue b/packages/primevue/src/cascadeselect/CascadeSelect.vue index ca2065ce1..dd79e0627 100644 --- a/packages/primevue/src/cascadeselect/CascadeSelect.vue +++ b/packages/primevue/src/cascadeselect/CascadeSelect.vue @@ -72,7 +72,8 @@ :optionGroupLabel="optionGroupLabel" :optionGroupChildren="optionGroupChildren" @option-change="onOptionChange" - @option-focus-change="onOptionFocusChange" + @option-focus-move-change="onOptionFocusMoveChange" + @option-focus-enter-change="onOptionFocusChangeEnter" :pt="pt" :unstyled="unstyled" /> @@ -303,25 +304,23 @@ export default { this.clicked = false; }, - onOptionChange(event) { + onOptionChange(event, isSelectable = true) { const { originalEvent, processedOption, isFocus, isHide } = event; if (isEmpty(processedOption)) return; - const { index, level, parentKey, children } = processedOption; + const { index, key, level, parentKey, children } = processedOption; const grouped = isNotEmpty(children); const root = isEmpty(processedOption.parent); const selected = this.isSelected(processedOption); if (selected) { - const { index, key, level, parentKey } = processedOption; - this.focusedOptionInfo = { index, level, parentKey }; this.activeOptionPath = this.activeOptionPath.filter((p) => key !== p.key && key.startsWith(p.key)); this.dirty = !root; } else { - const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey); + const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey && p.parentKey !== key); activeOptionPath.push(processedOption); @@ -329,10 +328,16 @@ export default { this.activeOptionPath = activeOptionPath; } - grouped ? this.onOptionGroupSelect(originalEvent, processedOption) : this.onOptionSelect(originalEvent, processedOption, isHide); + if (grouped) { + this.dirty = true; + this.onOptionGroupSelect(originalEvent, processedOption); + } else { + isSelectable && this.onOptionSelect(originalEvent, processedOption, isHide); + } + isFocus && focus(this.$refs.focusInput); }, - onOptionFocusChange(event) { + onOptionFocusMoveChange(event) { if (this.focusOnHover) { const { originalEvent, processedOption } = event; const { index, level, parentKey } = processedOption; @@ -341,6 +346,11 @@ export default { this.changeFocusedOptionIndex(originalEvent, index); } }, + onOptionFocusChangeEnter(event) { + if (this.dirty) { + this.onOptionChange(event, false); + } + }, onOptionSelect(event, processedOption, isHide = true) { const value = this.getOptionValue(processedOption?.option); diff --git a/packages/primevue/src/cascadeselect/CascadeSelectSub.vue b/packages/primevue/src/cascadeselect/CascadeSelectSub.vue index 91bad4584..fc04e58e8 100644 --- a/packages/primevue/src/cascadeselect/CascadeSelectSub.vue +++ b/packages/primevue/src/cascadeselect/CascadeSelectSub.vue @@ -17,7 +17,14 @@ :data-p-focus="isOptionFocused(processedOption)" :data-p-disabled="isOptionDisabled(processedOption)" > -
+
{{ getOptionLabelToRender(processedOption) }}