Skip to content

Commit

Permalink
Refactor #6538
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Oct 8, 2024
1 parent 0223158 commit 9d9ae35
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
66 changes: 34 additions & 32 deletions packages/primevue/src/cascadeselect/CascadeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
:optionGroupIcon="optionGroupIcon"
:optionGroupLabel="optionGroupLabel"
:optionGroupChildren="optionGroupChildren"
@option-change="onOptionChange"
@option-focus-move-change="onOptionFocusMoveChange"
@option-focus-enter-change="onOptionFocusChangeEnter"
@option-change="onOptionClick"
@option-focus-change="onOptionMouseMove"
@option-focus-enter-change="onOptionMouseEnter"
:pt="pt"
:unstyled="unstyled"
/>
Expand Down Expand Up @@ -304,53 +304,55 @@ export default {
this.clicked = false;
},
onOptionChange(event, isSelectable = true) {
const { originalEvent, processedOption, isFocus, isHide } = event;
onOptionChange(event) {
const { processedOption } = event;
if (isEmpty(processedOption)) return;
const { index, key, level, parentKey, children } = processedOption;
const grouped = isNotEmpty(children);
const root = isEmpty(processedOption.parent);
const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey && p.parentKey !== key);
if (grouped) {
activeOptionPath.push(processedOption);
}
this.focusedOptionInfo = { index, level, parentKey };
this.activeOptionPath = activeOptionPath;
},
onOptionClick(event) {
const { originalEvent, processedOption, isFocus, isHide } = event;
const { index, key, level, parentKey } = processedOption;
const grouped = this.isProccessedOptionGroup(processedOption);
const selected = this.isSelected(processedOption);
if (selected) {
this.focusedOptionInfo = { index, level, parentKey };
this.activeOptionPath = this.activeOptionPath.filter((p) => key !== p.key && key.startsWith(p.key));
this.dirty = !root;
this.focusedOptionInfo = { index, level, parentKey };
} else {
const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey && p.parentKey !== key);
activeOptionPath.push(processedOption);
if (grouped) {
this.onOptionChange(event);
} else {
const activeOptionPath = this.activeOptionPath.filter((p) => p.parentKey !== parentKey);
this.focusedOptionInfo = { index, level, parentKey };
this.activeOptionPath = activeOptionPath;
}
activeOptionPath.push(processedOption);
if (grouped) {
this.dirty = true;
this.onOptionGroupSelect(originalEvent, processedOption);
} else {
isSelectable && this.onOptionSelect(originalEvent, processedOption, isHide);
this.focusedOptionInfo = { index, level, parentKey };
this.activeOptionPath = activeOptionPath;
}
}
grouped ? this.onOptionGroupSelect(originalEvent, processedOption) : this.onOptionSelect(originalEvent, processedOption, isHide);
isFocus && focus(this.$refs.focusInput);
},
onOptionFocusMoveChange(event) {
if (this.focusOnHover) {
const { originalEvent, processedOption } = event;
const { index, level, parentKey } = processedOption;
this.focusedOptionInfo = { index, level, parentKey };
this.changeFocusedOptionIndex(originalEvent, index);
onOptionMouseEnter(event) {
if (this.dirty) {
this.onOptionChange(event);
}
},
onOptionFocusChangeEnter(event) {
if (this.dirty) {
this.onOptionChange(event, false);
} else {
this.onOptionFocusMoveChange(event);
onOptionMouseMove(event) {
if (this.focused) {
this.changeFocusedOptionIndex(event, event.processedOption.index);
}
},
onOptionSelect(event, processedOption, isHide = true) {
Expand Down
15 changes: 3 additions & 12 deletions packages/primevue/src/cascadeselect/CascadeSelectSub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
:optionGroupIcon="optionGroupIcon"
:optionGroupLabel="optionGroupLabel"
:optionGroupChildren="optionGroupChildren"
@option-change="onOptionChange"
@option-focus-change="onOptionFocusChange"
@option-focus-enter-change="onOptionFocusEnterChange"
@option-change="$emit('option-change', $event)"
@option-focus-change="$emit('option-focus-change', $event)"
@option-focus-enter-change="$emit('option-focus-enter-change', $event)"
:pt="pt"
:unstyled="unstyled"
/>
Expand Down Expand Up @@ -148,15 +148,6 @@ export default {
onOptionMouseMove(event, processedOption) {
this.$emit('option-focus-change', { originalEvent: event, processedOption });
},
onOptionChange(event) {
this.$emit('option-change', event);
},
onOptionFocusChange(event) {
this.$emit('option-focus-change', event);
},
onOptionFocusEnterChange(event) {
this.$emit('option-focus-enter-change', event);
},
containerRef(el) {
this.container = el;
},
Expand Down

0 comments on commit 9d9ae35

Please sign in to comment.