Skip to content

Commit

Permalink
feat(VTreeview): add modelValue which is equivalent to selected
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwu9145 committed Aug 7, 2024
1 parent e7b3e44 commit 2336637
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VTreeview.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"itemText": "Property on supplied `items` that contains its label text.",
"loadChildren": "A function used when dynamically loading children. If this prop is set, then the supplied function will be run if expanding an item that has a `item-children` property that is an empty array. Supports returning a Promise.",
"loadingIcon": "Icon used when node is in a loading state.",
"modelValue": "Allows one to control which nodes are selected. The array contains the values of currently selected items. It is equivalent to the `v-model:selected`",
"multipleActive": "When `true`, allows user to have multiple active nodes at the same time.",
"offIcon": "Icon used when node is not selected. Only visible when `selectable` is `true`.",
"onIcon": "Icon used when leaf node is selected or when a branch node is fully selected. Only visible when `selectable` is `true`.",
Expand Down
16 changes: 15 additions & 1 deletion packages/vuetify/src/labs/VTreeview/VTreeview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const makeVTreeviewProps = propsFactory({
expandIcon: '$treeviewExpand',
slim: true,
}), ['nav', 'openStrategy']),
modelValue: {
type: Array,
default: () => ([]),
},
}, 'VTreeview')

export const VTreeview = genericComponent<new <T>(
Expand All @@ -53,6 +57,7 @@ export const VTreeview = genericComponent<new <T>(
'update:opened': (val: unknown) => true,
'update:activated': (val: unknown) => true,
'update:selected': (val: unknown) => true,
'update:modelValue': (val: unknown) => true,
'click:open': (value: { id: unknown, value: boolean, path: unknown[] }) => true,
'click:select': (value: { id: unknown, value: boolean, path: unknown[] }) => true,
},
Expand All @@ -63,7 +68,16 @@ export const VTreeview = genericComponent<new <T>(
const baseColor = toRef(props, 'baseColor')
const color = toRef(props, 'color')
const activated = useProxiedModel(props, 'activated')
const selected = useProxiedModel(props, 'selected')
const model = useProxiedModel(props, 'modelValue')
const _selected = useProxiedModel(props, 'selected', props.modelValue)

const selected = computed({
get: () => _selected.value,
set (val) {
_selected.value = val
model.value = val
},
})

const vListRef = ref<VList>()

Expand Down

0 comments on commit 2336637

Please sign in to comment.