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(VAutocomplete): only clear search on blur in multiple mode or using chips/selection shots #19701

Conversation

elkofy
Copy link
Contributor

@elkofy elkofy commented Apr 26, 2024

Description

resolves #19543

Markup:

<template>
  <v-app>
    <v-container class="mx-2">
      <v-row>
        <v-col>
          <v-autocomplete
            v-model="model"
            :items="lista"
            density="compact"
            item-title="n"
            item-value="id"
            label="Label"
            title="Choose one"
            variant="outlined"
            hide-no-data
            @update:search="handleSearch"
          />
        </v-col>
        <v-col>
          <v-btn @click="searchCount = 0">Clean Search Count</v-btn>
        </v-col>
        <v-col>Model: {{ model }} Search Count: {{ searchCount }}</v-col>
      </v-row>
      <v-row>
        <v-col>
          <ol>
            <li>Choose one in list</li>
            <li>Click outside autocomplete</li>
            <li>Search occurs two times</li>
          </ol>
        </v-col>
      </v-row>
    </v-container>
  </v-app>
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  const model = ref(0)
  const searchCount = ref(0)
  const lista = ref([{ n: 'Choose one', id: 0 }, { n: 'test', id: 1 }, { n: 'test2', id: 2 }, { n: 'test3', id: 3 }])

  function handleSearch (value: string) {
    searchCount.value++
    console.log(value)
  }
</script>

@MajesticPotatoe MajesticPotatoe added T: bug Functionality that does not work as intended/expected C: VAutocomplete VAutocomplete labels Apr 30, 2024
@yuwu9145 yuwu9145 self-requested a review May 4, 2024 03:48
yuwu9145

This comment was marked as outdated.

@yuwu9145 yuwu9145 changed the title fix(AutoComplete): don't alter search value when out of focus fix(VAutocomplete): only clear search on blur in single mode May 6, 2024
@yuwu9145 yuwu9145 changed the title fix(VAutocomplete): only clear search on blur in single mode fix(VAutocomplete): only clear search on blur in single mode or using chips/selection shots May 6, 2024
@yuwu9145 yuwu9145 changed the title fix(VAutocomplete): only clear search on blur in single mode or using chips/selection shots fix(VAutocomplete): only clear search on blur in multiple mode or using chips/selection shots May 6, 2024
@yuwu9145
Copy link
Member

yuwu9145 commented May 6, 2024

<template>
  <v-app>
    <v-container class="mx-2">
      <v-row>
        <v-col>
          <v-autocomplete
            :items="list"
            density="compact"
            label="Multiple Chips"
            title="Choose one"
            variant="outlined"
            item-title="n"
            item-value="id"
            hide-no-data
            multiple 
            chips 
            @update:search="handleSeach"
          ></v-autocomplete>
          <v-autocomplete
            :items="list"
            density="compact"
            label="Multiple"
            title="Choose one"
            variant="outlined"
            item-title="n"
            item-value="id"
            hide-no-data
            multiple 
            @update:search="handleSeach"
          ></v-autocomplete>
          <v-autocomplete
            :items="list"
            density="compact"
            label="chips"
            title="Choose one"
            variant="outlined"
            item-title="n"
            item-value="id"
            hide-no-data
            chips 
            @update:search="handleSeach"
          ></v-autocomplete>
          <v-autocomplete
            :items="list"
            density="compact"
            label="Label"
            title="Choose one"
            variant="outlined"
            item-title="n"
            item-value="id"
            hide-no-data
            @update:search="handleSeach"
          ></v-autocomplete>
        </v-col>
        <v-col>
          <v-btn @click="searchCount = 0">Clean Search Count</v-btn>
        </v-col>
        <v-col>Model: {{ model }} Search Count: {{ searchCount }}</v-col>
      </v-row>
      <v-row>
        <v-col>
          <ol>
            <li>Choose one in list</li>
            <li>Click outside autocomplete</li>
            <li>Search occurs two times</li>
          </ol>
        </v-col>
      </v-row>
    </v-container>
  </v-app>
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  const model = ref(0)
  const searchCount = ref(0)
  const list = ref([{n: 'Choose one', id: 0},{ n: 'test', id: 1 }, { n: 'test2', id: 2 }, { n: 'test3', id: 3 }])

  function handleSeach(value: string) {
    searchCount.value++
    console.log(value)
  }
</script>

@johnleider johnleider merged commit d02e1b3 into vuetifyjs:master May 7, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VAutocomplete VAutocomplete T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][3.5.14] AutoComplete @update:search triggered on click
4 participants