Skip to content

[SelectMenu]: Placeholder value not shown if v-model is an empty string #4528

@antalasztrik

Description

@antalasztrik

Environment

Is this bug related to Nuxt or Vue?

Nuxt

Version

v3.2.0

Reproduction

The issue is really straight-forward, example code:

<script lang="ts" setup>
const value = ref("");
const items = ["Item 1", "Item 2", "Item 3"];
</script>

<template>
  <div class="space-y-4">
    <UFormField label="USelectMenu">
      <USelectMenu v-model="value" placeholder="Placeholder" :items />
    </UFormField>
    <UFormField label="USelect">
      <USelect v-model="value" placeholder="Placeholder" :items />
    </UFormField>
  </div>
</template>

Description

If the model-value is an empty string, the USelectMenu placeholder doesn't show. This behavior is different than the USelect component, where the placeholder is shown without having to use undefined as the v-model's value.

Additional context

I know I could use undefined for the value here, however in my real code the v-model is bound to a non-optional value, so if I were to initialize it as undefined, TypeScript would freak out. Also, because these components are really similar, these behaviors shouldn't differ in my opinion.

Image

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv3#1289

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions