Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VSelects): recognize empty string as no value #20742

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J-Sek
Copy link
Contributor

@J-Sek J-Sek commented Nov 27, 2024

Description

Selection controls should correctly reflect empty state. And most of the times empty string is perceived by end users as "no value". There is an edge case if "" is among options' values - it results in selection in VSelection and VAutocomplete, while VCombobox will not recognize it as selection because it does not care about item value (thus has hardcoded [''] and won't consume emptyValues from useItems)

fixes #20660

Markup:

<template>
  <v-app theme="dark">
    <v-container>
      <v-row>
        <v-col>
          <h4>Typical options</h4>
          <v-divider class="my-3" />
          <h5>VTextField</h5>
          <v-text-field v-model="msg1" :items="options1" clearable placeholder="Enter the message" />
          <h5>VSelect</h5>
          <v-select v-model="msg1" :items="options1" clearable placeholder="Select from the options" />
          <h5>VCombobox</h5>
          <v-combobox v-model="msg1" :items="options1" clearable placeholder="Select or type custom value" />
          <h5>VAutocomplete</h5>
          <v-autocomplete v-model="msg1" :items="options1" clearable placeholder="Type to find an item" />

          <pre>{{ JSON.stringify({ msg1 }) }}</pre>
        </v-col>
        <v-col>
          <h4>Options with empty string value</h4>
          <v-divider class="my-3" />
          <h5>VTextField</h5>
          <v-text-field v-model="msg2" :items="options2" clearable placeholder="Enter the message" />
          <h5>VSelect</h5>
          <v-select v-model="msg2" :items="options2" clearable placeholder="Select from the options" />
          <h5>VCombobox</h5>
          <v-combobox v-model="msg2" :items="options2" clearable placeholder="Select or type custom value" />
          <h5>VAutocomplete</h5>
          <v-autocomplete v-model="msg2" :items="options2" clearable placeholder="Type to find an item" />

          <pre>{{ JSON.stringify({ msg2 }) }}</pre>
        </v-col>
      </v-row>
    </v-container>
  </v-app>
</template>

<script setup>
import { ref } from 'vue'
const msg1 = ref('')
const msg2 = ref('')

const options1 = [
  { title: 'Alabama', value: 'AL' },
  { title: 'Alaska', value: 'AK' },
  { title: 'American Samoa', value: 'AS' },
  { title: 'Arizona', value: 'AZ' },
  { title: 'Arkansas', value: 'AR' },
]
const options2 = [
  { title: "(I don't want to disclose)", value: '' },
  { title: 'California', value: 'CA' },
  { title: 'Colorado', value: 'CO' },
  { title: 'Connecticut', value: 'CT' },
  { title: 'Delaware', value: 'DE' },
]
</script>

@J-Sek J-Sek added T: bug Functionality that does not work as intended/expected C: Selection controls labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Selection controls T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Closed and to be deleted
1 participant