Skip to content

Commit

Permalink
fix(defaults): remove required default and add chain operator
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Apr 27, 2023
1 parent 35b9411 commit eb00082
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vuetify/src/composables/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,26 @@ function propIsDefined (vnode: VNode, prop: string) {
typeof vnode.props?.[toKebabCase(prop)] !== 'undefined'
}

export function useDefaults (props: Record<string, any>, name?: string, defaults = injectDefaults()) {
export function useDefaults (
props: Record<string, any> = {},
name?: string,
defaults = injectDefaults()
) {
const vm = getCurrentInstance('useDefaults')

name = name ?? vm.type.name ?? vm.type.__name
if (!name) {
throw new Error('[Vuetify] Could not determine component name')
}

const componentDefaults = computed(() => defaults.value![props._as ?? name])
const componentDefaults = computed(() => defaults.value?.[props._as ?? name])
const _props = new Proxy(props, {
get (target, prop) {
const propValue = Reflect.get(target, prop)
if (prop === 'class' || prop === 'style') {
return [componentDefaults.value?.[prop], propValue].filter(v => v != null)
} else if (typeof prop === 'string' && !propIsDefined(vm.vnode, prop)) {
return componentDefaults.value?.[prop] ?? defaults.value!.global?.[prop] ?? propValue
return componentDefaults.value?.[prop] ?? defaults.value?.global?.[prop] ?? propValue
}
return propValue
},
Expand Down

0 comments on commit eb00082

Please sign in to comment.