Skip to content

Commit 2a74859

Browse files
committed
fix(defaults): skip undefined values
fixes #17845
1 parent d34d9bc commit 2a74859

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

packages/docs/src/pages/en/getting-started/upgrade-guide.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,21 @@ Removed the **$text-field-details-padding-inline** Sass variable.
367367
+ $input-details-padding-inline: <value>
368368
);
369369
```
370+
371+
## Defaults
372+
373+
`undefined` values are now skipped when merging prop defaults. This button would have been grey in v3, but is now green:
374+
375+
```jsx
376+
createVuetify({
377+
defaults: {
378+
VBtn: { color: 'green' },
379+
},
380+
})
381+
382+
<VDefaultsProvider :defaults="{ VBtn: { color: undefined }}">
383+
<VBtn />
384+
</VDefaultsProvider>
385+
```
386+
387+
Replace `undefined` with `null` if you do actually want it to override the global default value.

packages/vuetify/src/components/VColorPicker/VColorPicker.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ export const VColorPicker = defineComponent({
126126

127127
provideDefaults({
128128
VSlider: {
129-
color: undefined,
130-
trackColor: undefined,
131-
trackFillColor: undefined,
129+
color: null,
130+
trackColor: null,
131+
trackFillColor: null,
132132
},
133133
})
134134

packages/vuetify/src/composables/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function provideDefaults (
7575
}
7676

7777
return properties.prev
78-
? mergeDeep(properties.prev, properties)
78+
? mergeDeep(properties.prev, properties, undefined, (_, v) => v !== undefined)
7979
: properties
8080
}) as ComputedRef<DefaultsInstance>
8181

packages/vuetify/src/util/helpers.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ export function mergeDeep (
450450
source: Record<string, any> = {},
451451
target: Record<string, any> = {},
452452
arrayFn?: (a: unknown[], b: unknown[]) => unknown[],
453+
targetCondition?: (k: string, v: unknown) => boolean,
453454
) {
454455
const out: Record<string, any> = {}
455456

@@ -458,13 +459,18 @@ export function mergeDeep (
458459
}
459460

460461
for (const key in target) {
461-
const sourceProperty = source[key]
462462
const targetProperty = target[key]
463463

464+
if (targetCondition && !targetCondition(key, targetProperty)) {
465+
continue
466+
}
467+
468+
const sourceProperty = source[key]
469+
464470
// Only continue deep merging if
465471
// both properties are plain objects
466472
if (isPlainObject(sourceProperty) && isPlainObject(targetProperty)) {
467-
out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn)
473+
out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn, targetCondition)
468474

469475
continue
470476
}

0 commit comments

Comments
 (0)