Skip to content

Commit

Permalink
fix(tree-select): add emit modelValue (#2461)
Browse files Browse the repository at this point in the history
  • Loading branch information
MomoPoppy authored and zzcr committed Nov 4, 2024
1 parent 8ae85c6 commit 8a9f812
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion packages/renderless/src/tree-select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@ 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],
value: node[props.valueField]
}
})
)

emit('change', currentValue)
emit('update:modelValue', currentValue)
}
}
6 changes: 3 additions & 3 deletions packages/renderless/src/tree-select/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ 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
})

Object.assign(api, {
state,
filter: filter({ vm }),
nodeClick: nodeClick({ props, vm }),
check: check({ props, vm })
check: check({ props, vm, emit })
})

return api
Expand Down

0 comments on commit 8a9f812

Please sign in to comment.