From 8a9f8126f08da0d113dd0a4e2135514e1a2576ff Mon Sep 17 00:00:00 2001 From: MomoPoppy <125256456+MomoPoppy@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:29:40 -0700 Subject: [PATCH] fix(tree-select): add emit modelValue (#2461) --- packages/renderless/src/tree-select/index.ts | 12 +++++++++++- packages/renderless/src/tree-select/vue.ts | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/renderless/src/tree-select/index.ts b/packages/renderless/src/tree-select/index.ts index a9a901731f..b3da78569e 100644 --- a/packages/renderless/src/tree-select/index.ts +++ b/packages/renderless/src/tree-select/index.ts @@ -17,16 +17,23 @@ export const nodeClick = } }) + emit('change', data[props.valueField]) + emit('update:modelValue', data[props.valueField]) + vm.$refs.baseSelectRef.hidePanel() } } export const check = - ({ props, vm }) => + ({ props, vm, emit }) => (data, { checkedNodes }) => { if (props.multiple) { + const currentValue = [] + vm.$refs.baseSelectRef.updateSelectedData( checkedNodes.map((node) => { + currentValue.push(node[props.valueField]) + return { ...node, currentLabel: node[props.textField], @@ -34,5 +41,8 @@ export const check = } }) ) + + emit('change', currentValue) + emit('update:modelValue', currentValue) } } diff --git a/packages/renderless/src/tree-select/vue.ts b/packages/renderless/src/tree-select/vue.ts index 5c01c87d41..ebb2d51237 100644 --- a/packages/renderless/src/tree-select/vue.ts +++ b/packages/renderless/src/tree-select/vue.ts @@ -2,11 +2,11 @@ import { filter, nodeClick, check } from './index' export const api = ['state', 'filter', 'nodeClick', 'check'] -export const renderless = (props, { reactive }, { vm }) => { +export const renderless = (props, { reactive, computed }, { vm, emit }) => { const api = {} const state = reactive({ - value: props.modelValue, + value: computed(() => props.modelValue), treeData: props.treeOp.data }) @@ -14,7 +14,7 @@ export const renderless = (props, { reactive }, { vm }) => { state, filter: filter({ vm }), nodeClick: nodeClick({ props, vm }), - check: check({ props, vm }) + check: check({ props, vm, emit }) }) return api