From 85092d439c6b39a02238cfe9960b91d2e38515b0 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Oct 2021 14:14:04 +0300 Subject: [PATCH 1/5] fix: fix allLevelShown in multiple mode --- .../src/QCascaderTags/QCascaderTags.vue | 6 ++++-- .../QCascader/src/helpers/findLabel.ts | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/qComponents/QCascader/src/helpers/findLabel.ts diff --git a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue index 0a113eb2..462e3495 100644 --- a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue +++ b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue @@ -33,6 +33,7 @@ import { defineComponent, inject, computed } from 'vue'; import QTag from '@/qComponents/QTag/src/QTag.vue'; import findFullPath from '../helpers/findFullPath'; +import findLabel from '../helpers/findLabel'; import type { QCascaderProvider } from '../types'; import type { TagItem, QCascaderTagsInstance } from './types'; @@ -61,8 +62,9 @@ export default defineComponent({ return modelValue.map(value => ({ value, - label: - findFullPath(qCascader.options.value, value)?.join(separator) ?? '' + label: qCascader.allLevelsShown.value + ? findFullPath(qCascader.options.value, value)?.join(separator) ?? '' + : findLabel(qCascader.options.value, value) ?? '' })); }); diff --git a/src/qComponents/QCascader/src/helpers/findLabel.ts b/src/qComponents/QCascader/src/helpers/findLabel.ts new file mode 100644 index 00000000..e28ce5a8 --- /dev/null +++ b/src/qComponents/QCascader/src/helpers/findLabel.ts @@ -0,0 +1,21 @@ +import type { Nullable } from '#/helpers'; + +import type { Option } from '../types'; + +const findLabel = ( + branches: Nullable, + find: Nullable +): Nullable => { + const found = branches?.find(branch => branch.value === find)?.label ?? null; + const children = branches + ?.filter(branch => branch.children) + .map(branch => branch.children) + .flat(1) as Option[]; + + if (!found && children?.length) { + return findLabel(children, find); + } + return found; +}; + +export default findLabel; From c79636108bfe2d972ce101d87ae1d861088f1a6d Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Oct 2021 14:30:53 +0300 Subject: [PATCH 2/5] feat: add ability to select branch node in default mode --- .../QCascader/src/QCascaderRow/QCascaderRow.vue | 7 ++++++- src/qComponents/QCascader/src/QCascaderRow/types.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue b/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue index bf95a3c9..f081bc3b 100644 --- a/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue +++ b/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue @@ -9,7 +9,7 @@ @keyup.enter="handleEnterKeyUp" >
qCascader.multiple.value ?? false ); + const isCheckStrictly = computed( + () => qCascader.checkStrictly.value ?? false + ); + const childStatuses = computed(() => { if (!qCascader.multiple.value || qCascader.checkStrictly.value) return []; return getChildStatuses(props.row, qCascader.modelValue.value); @@ -167,6 +171,7 @@ export default defineComponent({ return { rootClasses, isMultiple, + isCheckStrictly, isChecked, isIndeterminate, isIconShown, diff --git a/src/qComponents/QCascader/src/QCascaderRow/types.ts b/src/qComponents/QCascader/src/QCascaderRow/types.ts index c93666c0..5c26706b 100644 --- a/src/qComponents/QCascader/src/QCascaderRow/types.ts +++ b/src/qComponents/QCascader/src/QCascaderRow/types.ts @@ -16,6 +16,7 @@ export interface QCascaderRowProps { export interface QCascaderRowInstance { rootClasses: ComputedRef>; isMultiple: ComputedRef; + isCheckStrictly: ComputedRef; isChecked: ComputedRef; isIndeterminate: ComputedRef; isIconShown: ComputedRef; From 52eaef217364590f27682cfb556b68545daa0fee Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Oct 2021 15:30:08 +0300 Subject: [PATCH 3/5] fix: select row only via checkbox if checkStrictly --- src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue b/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue index f081bc3b..19e9e65e 100644 --- a/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue +++ b/src/qComponents/QCascader/src/QCascaderRow/QCascaderRow.vue @@ -144,7 +144,7 @@ export default defineComponent({ const handleClick = (): void => { if (props.row.disabled) return; - if (!isMultiple.value && !props.row.children) { + if (!isMultiple.value && !props.row.children && !isCheckStrictly.value) { ctx.emit('check', props.row, isChecked.value); } From 09827b6b5f332309a6dd878f66ca88ee9d3671be Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Oct 2021 15:53:41 +0300 Subject: [PATCH 4/5] fix: remove findLabel, use findFullPath instead --- .../src/QCascaderTags/QCascaderTags.vue | 16 +++++++------- .../QCascader/src/helpers/findLabel.ts | 21 ------------------- 2 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 src/qComponents/QCascader/src/helpers/findLabel.ts diff --git a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue index 462e3495..46de1163 100644 --- a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue +++ b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue @@ -33,7 +33,6 @@ import { defineComponent, inject, computed } from 'vue'; import QTag from '@/qComponents/QTag/src/QTag.vue'; import findFullPath from '../helpers/findFullPath'; -import findLabel from '../helpers/findLabel'; import type { QCascaderProvider } from '../types'; import type { TagItem, QCascaderTagsInstance } from './types'; @@ -60,12 +59,15 @@ export default defineComponent({ if (!Array.isArray(modelValue)) return []; - return modelValue.map(value => ({ - value, - label: qCascader.allLevelsShown.value - ? findFullPath(qCascader.options.value, value)?.join(separator) ?? '' - : findLabel(qCascader.options.value, value) ?? '' - })); + return modelValue.map(value => { + const fullPath = findFullPath(qCascader.options.value, value); + return { + value, + label: qCascader.allLevelsShown.value + ? fullPath?.join(separator) ?? '' + : fullPath?.[fullPath?.length - 1] ?? '' + }; + }); }); const handleTagClose = (value: string | number): void => { diff --git a/src/qComponents/QCascader/src/helpers/findLabel.ts b/src/qComponents/QCascader/src/helpers/findLabel.ts deleted file mode 100644 index e28ce5a8..00000000 --- a/src/qComponents/QCascader/src/helpers/findLabel.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { Nullable } from '#/helpers'; - -import type { Option } from '../types'; - -const findLabel = ( - branches: Nullable, - find: Nullable -): Nullable => { - const found = branches?.find(branch => branch.value === find)?.label ?? null; - const children = branches - ?.filter(branch => branch.children) - .map(branch => branch.children) - .flat(1) as Option[]; - - if (!found && children?.length) { - return findLabel(children, find); - } - return found; -}; - -export default findLabel; From 34ca773cfc9cf0e4024ffd4f015a41239d22ae50 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Oct 2021 16:03:09 +0300 Subject: [PATCH 5/5] fix: fix code style --- .../QCascader/src/QCascaderTags/QCascaderTags.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue index 46de1163..79773d52 100644 --- a/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue +++ b/src/qComponents/QCascader/src/QCascaderTags/QCascaderTags.vue @@ -61,11 +61,13 @@ export default defineComponent({ return modelValue.map(value => { const fullPath = findFullPath(qCascader.options.value, value); + const label = qCascader.allLevelsShown.value + ? fullPath?.join(separator) + : fullPath?.[fullPath?.length - 1]; + return { value, - label: qCascader.allLevelsShown.value - ? fullPath?.join(separator) ?? '' - : fullPath?.[fullPath?.length - 1] ?? '' + label: label ?? '' }; }); });