Skip to content

Commit ebdc1c8

Browse files
committed
fix: vcombobox empty string initial value not showing placeholder
1 parent bb54746 commit ebdc1c8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/vuetify/src/components/VCombobox/VCombobox.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ export const VCombobox = genericComponent<new <
132132
const vVirtualScrollRef = ref<VVirtualScroll>()
133133
const selectionIndex = shallowRef(-1)
134134
let cleared = false
135-
const { items, transformIn, transformOut } = useItems(props)
135+
const { items, transformIn, transformOut, emptyValues } = useItems(props)
136136
const { textColorClasses, textColorStyles } = useTextColor(() => vTextFieldRef.value?.color)
137137
const model = useProxiedModel(
138138
props,
139139
'modelValue',
140140
[],
141-
v => transformIn(wrapInArray(v)),
141+
v => transformIn(v === null ? [null] : wrapInArray(v, emptyValues.value)),
142142
v => {
143143
const transformed = transformOut(v)
144144
return props.multiple ? transformed : (transformed[0] ?? null)
@@ -477,7 +477,8 @@ export const VCombobox = genericComponent<new <
477477
slots['append-item'] ||
478478
slots['no-data']
479479
)
480-
const isDirty = model.value.length > 0
480+
const isEmptyString = model.value.length === 1 && model.value[0].value === ''
481+
const isDirty = model.value.length > 0 && !isEmptyString
481482
const textFieldProps = VTextField.filterProps(props)
482483

483484
return (

packages/vuetify/src/composables/list-items.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export function transformItems (
123123
export function useItems (props: ItemProps) {
124124
const items = computed(() => transformItems(props, props.items))
125125
const hasNullItem = computed(() => items.value.some(item => item.value === null))
126+
const allValues = computed(() => items.value.map(item => item.value))
127+
const emptyValues = computed(() => ['', null, undefined].filter(v => !allValues.value.includes(v)))
126128

127129
const itemsMap = shallowRef<Map<Primitive, ListItem[]>>(new Map())
128130
const keylessItems = shallowRef<ListItem[]>([])
@@ -204,5 +206,5 @@ export function useItems (props: ItemProps) {
204206
: value.map(({ value }) => value)
205207
}
206208

207-
return { items, transformIn, transformOut }
209+
return { items, transformIn, transformOut, emptyValues }
208210
}

packages/vuetify/src/util/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,12 @@ export function arrayDiff (a: any[], b: any[]): any[] {
389389

390390
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
391391
export function wrapInArray<T> (
392-
v: T | null | undefined
392+
v: T | null | undefined,
393+
emptyValues: any[] = []
393394
): T extends readonly any[]
394395
? IfAny<T, T[], T>
395396
: NonNullable<T>[] {
396-
return v == null
397+
return v == null || emptyValues.includes(v)
397398
? [] as any
398399
: Array.isArray(v)
399400
? v as any : [v] as any

0 commit comments

Comments
 (0)