Chips Style Vuetify Autocomplete Menu / Dropdown Feature

I am looking to change the appearance of the items in the dropdown menu of my Autocomplete Box. Vuetify-Autocomplete

Currently, it displays the standard style for each item: Current

<v-autocomplete
chips
deletable-chips
multiple
v-model="selectedTags"
:items="tags"
></v-autocomplete>

However, I would like the items to be displayed in a chips-style format like this:

Chips-Style

If possible, I would also like to assign specific colors to each tag. I am currently showcasing them in a table using the normal "v-chip" component, which is working well! Table with colored chips

I have attempted tweaking CSS and the V-autocomplete component, but encountered errors each time.

I tried searching for something like

:menu-props="{
nudgeBottom: 15 + 'px',
zIndex: 2,
allowOverflow,
rounded: 'xl'      // <-- Here ✅
}"

as shown in this issue on Stackoverflow, but for the properties/items within the menu instead of the menu itself.

Another solution could be creating a custom version that doesn't use the dropdown, where I check if the string is in one of the chips in my chip-list and display them below the search bar. However, this would mean sacrificing some cool autocomplete features.

I am unable to add pictures at the moment due to being new here. Apologies for that!

I hope I have provided all necessary information.

Answer №1

Take a look at this amazing codesandbox I created: https://codesandbox.io/s/stack-86921421-bcdfv?file=/src/components/AutoChips.vue

Certain Vuetify components come with a feature known as slots, which allow you to personalize them according to your requirements. For example, the v-autocomplete component includes an item slot that enables you to customize the items in the displayed list by creating a custom template.

<v-autocomplete
   v-model="values"
   :items="items"
   chips
   deletable-chips
   multiple
   label="Customize Autocomplete Items"
>
   <template v-slot:item="{ item, on, attrs }">
      <v-list-item v-on="on" v-bind="attrs" #default="{ active }">
         <v-list-item-action>
            <v-checkbox :color="getChipColor(item)" :input-value="active"></v-checkbox>
         </v-list-item-action>
         <v-list-item-content>
            <v-list-item-title>                      
               <v-chip dark :color="getChipColor(item)"> {{ item }} </v-chip>
            </v-list-item-title>
         </v-list-item-content>
      </v-list-item>
   </template>
</v-autocomplete>

You can assign a custom color to each v-chip by implementing a simple method and providing the item value as an argument.

getChipColor(item) {
   switch (item) {
      case 'foo':
         return 'red darken-2' 
      case 'bar':
         return 'green darken-2' 
      case 'fizz':
         return 'orange darken-2' 
      case 'buzz':
         return 'purple darken-2'          
      default:
         return 'grey lighten-2'
   }
}

If you wish to customize the selected chips as well, you can achieve it by making adjustments to the selection slot. For more information on all available slots for the v-autocomplete component, refer to its API documentation page. https://vuetifyjs.com/en/api/v-autocomplete/#slots

https://i.sstatic.net/3zJ6F.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing the screen size of a panel using asp.net and c#

When my screen size reaches 480px, I want to remove one menu and replace it with another. The solution I'm considering is creating two panels. In this setup, I would set menu1 to false when the screen size is less than 480px and menu2 to true. Conve ...

constructing a nested container using XMLHttpRequest

I am working on creating a nested div-container structure using AJAX and adding the text "Hello World" to the inner container. The outer container serves as a holder for the inner container in this case. Below is the code I have written: index.html: ...

How to Retrieve Error Message from Response in Django REST Framework When Making a 400 Bad Request

I have a setup where I'm using Vue with DRF for my application. Whenever there is an issue with the form data and it is sent to the API, it responds with a 400 Bad request error as expected. The response in the Network tab provides a clear validation ...

Discover the indices of elements that, when their values are added together, equal x

I have an array with elements structured like this: var x = 17; var arr = [{ value:2, quantity: 4 }, { value:8, quantity: 1 }, { value:3, quantity: 3 }]; How can I identify the indexes of elements that would add up to equal the x number? For example, in ...

Problem with applying ng-class directive in AngularJS

I am currently developing an application using AngularJs and Bootstrap. My goal is to display the title of a 'scenario' with different styling based on its status, along with a specific icon. Initially, I attempted the following approach: <s ...

"Using JavaScript to Make Requests on Mobile Devices via HTTP

Greetings everyone, I have a query regarding implementing an endpoint api in my mobile application. For instance, suppose I have a server handling data and I want to notify my mobile application about new updates by sending a post request. Is this feasibl ...

Tips for utilizing the Apollo cache consistently during page transitions in NextJs

In the official examples repository of NextJS, I found this apolloClient.js file: import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client' import { concatPagination } from '@apollo/client/utilities' import merge from &apos ...

What are the consequences of excluding a callback in ReactJs that may lead to dysfunctionality?

<button onClick = { () => this.restart()}>Restart</button> While going through a ReactJs tutorial, I encountered a game page which featured a restart button with the code snippet mentioned above. However, when I tried to replace it with the ...

Managing data in a database on Discord using JavaScript to automatically delete information once it has expired

Recently, I implemented a premium membership feature for my discord bot. However, I encountered an issue where the membership time starts counting down before the intended start time. To resolve this, I am looking to automatically delete the data from the ...

Access the outcome by utilizing a for loop

Within my code, I am utilizing both a function and a loop: var songs = Musics.searchSongs(query).then(function(rs) { return rs; }); for (var i = 0; i < songs.length; i++) { console.log(songs[i]); } I am now looking for a way to execute the ...

Django CSS not loading properly on webpage after initial load

I am having trouble understanding why the main.css file is not loading properly in my Django project. I am using the skeleton boilerplate and trying to change the background color, but the changes are not reflecting on the webpage. It's strange becaus ...

The Contact.php page has the ability to send emails, however, the content of the

I have recently added a contact form to my website using a template. Although I am able to send and receive email messages successfully, I am facing an issue where the actual message content entered by users is not being received in my Inbox. Here is a sc ...

Is there a way to modify the scroll ion-content's color scheme?

Is there a way to change the scroll color in Ionic to green, specifically for ion-content? Any suggestions on how I can achieve this? Below is my HTML code: <ion-header> <ion-toolbar> <ion-buttons slot="start"> ...

I need to use JavaScript to create HTML to PDF and then upload the PDF file to a SharePoint Document Library

Our current project requires us to convert HTML to PDF and save it in a SharePoint Document Library. While we have successfully converted the HTML to PDF using Kendo plugin, we are facing challenges with storing it in SharePoint. It's worth noting th ...

Is there a way for me to receive a success message when I successfully set data in Firebase?

I want to retrieve the orderId after successfully adding an order to the Realtime database using angularfirestore. What should I use after set() method to return the orderId? The structure of my order object is as follows: const orderObj: Order = { pay ...

Obtaining a substantial pdf file using html2pdf

While using html2pdf to generate a PDF of my website, I noticed that the downloaded PDF ends up being 14 pages long. However, after approximately 12 pages, all the colored elements seem to disappear. On mobile screens, this issue occurs even sooner, around ...

Angular pagination with enforced ellipses using Bootstrap

I have encountered an issue with pagination on the Plnkr I created. You can check out the problem here: http://plnkr.co/edit/YQAUCg5vjcgS1BEGB4nY?p=preview. Essentially, I have a large number of pages and I have set the attribute force-ellipses = true to ...

Personalized Angular dropdown menu

Recently, I've started delving into angularJS and I'm eager to create dropdowns and tabs using both bootstrap and angular. Although there is a comprehensive angular bootstrap library available, I prefer not to use it in order to gain a deeper und ...

Troubleshooting a jQuery Drop-Down Problem

My dropdown menu is not working as expected. I want to show the sub-menu when clicking on an item, and remove the previous sub-menu when clicking or blurring on another menu by removing the drop-down class. However, my current jQuery code does not seem to ...

How can I reduce the size of a Bootstrap 5 carousel that spans the entire screen?

As someone new to web development, I have found using bootstrap to be extremely helpful. However, I am currently struggling with creating a carousel for my website. My goal is to display some pictures in one corner of the page, but the carousel keeps str ...