From eb0008221459900d828f1635b1fa4f902862af50 Mon Sep 17 00:00:00 2001 From: John Leider Date: Thu, 27 Apr 2023 09:05:36 -0500 Subject: [PATCH] fix(defaults): remove required default and add chain operator --- packages/vuetify/src/composables/defaults.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/vuetify/src/composables/defaults.ts b/packages/vuetify/src/composables/defaults.ts index ed9278f014c..b452ad2bc3b 100644 --- a/packages/vuetify/src/composables/defaults.ts +++ b/packages/vuetify/src/composables/defaults.ts @@ -84,7 +84,11 @@ function propIsDefined (vnode: VNode, prop: string) { typeof vnode.props?.[toKebabCase(prop)] !== 'undefined' } -export function useDefaults (props: Record, name?: string, defaults = injectDefaults()) { +export function useDefaults ( + props: Record = {}, + name?: string, + defaults = injectDefaults() +) { const vm = getCurrentInstance('useDefaults') name = name ?? vm.type.name ?? vm.type.__name @@ -92,14 +96,14 @@ export function useDefaults (props: Record, name?: string, defaults 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 },