Skip to content

Commit ca3430f

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

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
@@ -133,13 +133,13 @@ export const VCombobox = genericComponent<new <
133133
const vVirtualScrollRef = ref<VVirtualScroll>()
134134
const selectionIndex = shallowRef(-1)
135135
let cleared = false
136-
const { items, transformIn, transformOut } = useItems(props)
136+
const { items, transformIn, transformOut, emptyValues } = useItems(props)
137137
const { textColorClasses, textColorStyles } = useTextColor(() => vTextFieldRef.value?.color)
138138
const model = useProxiedModel(
139139
props,
140140
'modelValue',
141141
[],
142-
v => transformIn(wrapInArray(v)),
142+
v => transformIn(v === null ? [null] : wrapInArray(v, emptyValues.value)),
143143
v => {
144144
const transformed = transformOut(v)
145145
return props.multiple ? transformed : (transformed[0] ?? null)
@@ -478,7 +478,8 @@ export const VCombobox = genericComponent<new <
478478
slots['append-item'] ||
479479
slots['no-data']
480480
)
481-
const isDirty = model.value.length > 0
481+
const isEmptyString = model.value.length === 1 && model.value[0].value === ''
482+
const isDirty = model.value.length > 0 && !isEmptyString
482483
const textFieldProps = VTextField.filterProps(props)
483484

484485
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)