What is the best way to implement a hover feature on a Vue / Vuetify Autocomplete dropdown list?

I'm not very experienced with Vue and I'm finding it a bit complex to grasp. Perhaps you guys can provide the "best practice" or most efficient solution for my issue:

I have an autocomplete dropdown box. When expanded, it shows a list with clickable items. I want to retrieve the information of the item that the mouse hovers over in the list. For example, the method "doFunnyStuff" would pass the data of the hovered object to a function when hovering over it, and perform some action with it (possibly externally)

Thank you in advance for any helpful suggestions!

<template>
  <v-autocomplete
    v-model="selected"
    dense
    outlined
    hide-details
    return-object
    background-color="white"
    light
    :placeholder="placeholder"
    hide-no-data
    style="width: 500px"
    :loading="loading"
    :search-input.sync="query"
    :items="items"
    clearable
  >
    <template slot="selection" slot-scope="{ item }" return-object>
      <v-list-item @mouseenter="doFunnyStuff(item)">
        <v-list-item-content>
          <v-list-item-title> {{ item.text }}} </v-list-item-title>
        </v-list-item-content>
      </v-list-item>
    </template></v-autocomplete
  >
</template>
    </template>

Answer №1

It's possible that I may have misunderstood your query, but if you're looking to perform actions on a hovered item within an expanded list, you should utilize the item slot instead of the selection.

The selection slot is specifically for the item that is currently selected at the top of the component. Therefore, your code will only work when you hover over the already selected item.

The Mouseenter event isn't directly associated with any component in Vuetify. It's a JavaScript event that can be added to any component, provided it hasn't been previously added by Vuetify or another library.

Here's how you can adjust your code:

<div id="app">
  <v-app id="inspire">
    <v-autocomplete
      v-model="value"
      :items="items"
      dense
      filled
      label="Filled"
    >
      <template #item="{ item, on, attrs }">
        <v-list-item @mouseenter="doFunnyStuff(item)" v-on="on" v-bind="attrs">
          <v-list-item-content>
            <v-list-item-title> {{ item }} </v-list-item-title>
          </v-list-item-content>
        </v-list-item>
      </template>
    </v-autocomplete>
    <div>
      <p>{{ hoveredItem }}</p>
    </div>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    items: ['foo', 'bar', 'fizz', 'buzz'],
    value: null,
    hoveredItem: "not hovered yet"
  }),
  methods: {
    doFunnyStuff (item) {
      this.hoveredItem = item;
    }
  }
})

You can view an example on Codepen here

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

Conceal an item if it is located past a certain point (from the viewpoint of the camera)

In the realm of three-dimensional space, imagine a cube represented by a THREE.Mesh that has been added to the scene. cube.position.set( 10, 10, 10 ); scene.add( cube ); Once you have rotated the scene using your mouse, the goal is to cleverly conceal th ...

Angular 8 allows for the creation of custom checkboxes with unique content contained within the checkbox itself, enabling multiple selection

I'm in need of a custom checkbox with content inside that allows for multiple selections, similar to the example below: https://i.sstatic.net/CbNXv.png <div class="row"> <div class="form-group"> <input type ...

How to unselect a radio button in Vue using a button, similar to using vanilla JavaScript

Looking to translate this vanilla JavaScript code into Vue, here's the original: const radio = document.querySelector('#radio'); const boton = document.querySelector('#boton'); boton.addEventListener('click', () => { ...

How to prevent npm from being accessed through the command prompt

I recently began working on a ReactJs project. However, I am facing an issue where after starting npm in Command Prompt, I am unable to enter any text. Should I close the cmd window or is there a way to stop npm? You can now access your project at the fol ...

Increase the height of an element based on the content of the text within

Today I am facing a challenge: I need the text below to change when I click on one of these icons: https://i.sstatic.net/28xEF.png Luckily, it works with the following code: CSS .games-text { background-color: $color-primary; & p { m ...

Keeping track of both the search query and the results

I have stored the current search term in a state using e.target.value as searchField, but when I clear the input value, I can no longer use it. I want to display a message in the body informing the user that their specific searched term yielded no results, ...

What causes my animation to “reset” upon adding a new element using innerHTML?

One of the functionalities on my webpage involves a script that inserts a div called "doge" using innerHTML when a button is clicked. Additionally, there is a CSS keyframes animation applied to another div on the same page. However, whenever the button is ...

Is there a similar feature to RxJs version 4's ofArrayChanges in RxJs version 5?

Currently utilizing Angular2 and attempting to monitor changes in an array. The issue lies with only having RxJs5 available, which appears to lack this specific functionality. ...

Identify the browser dimensions and implement CSS styling for all screen resolutions

I am currently facing an issue with a function that I have created to apply CSS changes to a menu based on browser resizing and different resolutions. The problem lies in the fact that my function does not seem to be correctly interpreted by the browser. W ...

What is the most effective way to loop through HTML elements using wildcards in Puppeteer to extract innerText?

Seeking insights for educational purposes, I am in search of the reviews on this specific page . Each page contains 10 reviews, and I have a set of HTML selectors (previously used code) to extract these comments: #review_593124597 > div:nth-child(1) &g ...

When sending a single apostrophe as a parameter in an AJAX post request, it will result in an error

JavaScript Code: var name = jQuery("#name1").val(); jQuery.ajax({ url: siteUrl + 'search/ind', type: 'POST', data: { name: name, }, success: function(data) { jQuery('#input').val(''); } } ...

What is the method used by React or Next to prevent the <a> tag from refreshing the page while still loading content?

I'm currently diving into the world of NextJS and utilizing the Link component from the 'next/link' package. One thing that has been puzzling me is how the <Link> component ultimately renders an <a> tag with a href='/tosomew ...

Develop a dynamic button using JavaScript to fetch information from an array

I'm struggling with incorporating this button creation code into my HTML using JavaScript. The code for creating the button element in JS file looks like this: var numery = ['A','B','C']; var numer = document.createE ...

Is it possible to save the project by generating incremental JSON diffs?

In the process of developing a web-based paint program, I have implemented a system where the user's artwork state is saved as a json object. Each time an addition is made to the client's undo stack (which consists of json objects describing the ...

How can type-ahead auto-completion be effectively implemented for a vast amount of data?

As a .NET WinForms/ASP.NET developer, I have some technology agnostic questions regarding the implementation of "type-ahead auto-completion" for a large dataset. While I would appreciate a reference implementation or detailed discussion, I have the followi ...

Utilizing ReactJS to display a new screen post-login using a form, extracting information from Express JSON

I am facing a challenge with updating the page on my SPA application after a successful login. I have successfully sent the form data to the API using a proxy, but now the API responds with a user_ID in JSON format. However, I'm struggling with making ...

Top method for displaying loading popup using $http

As a newcomer to Angular, I am curious to know if it's possible to achieve the following scenario and also where I can find documentation to help me get started. The scenario: In my MEAN app, there is currently a 'loading...' popup controll ...

Executing Javascript in a Bootstrap 4 modal using Rails

I am working on a Rails 5.1 application where I'm implementing a patient record creation functionality using Ajax within a form using coffeescript/JS. The code I have been using for this task works seamlessly: _form.html.erb <div class="modal fad ...

Transforming an array of strings into a visual representation

Having an issue parsing a string array for Highcharts consumption. The chart renders when values are static, but not when passed as an array. I have validated the string being parsed here. The main issue appears to be with this specific line: //This work ...

methods to retrieve value from a javascript function

Just a quick inquiry - what's the best way to pass or return a value from a function? Here is my code: function numberOfDivs(){ var numberOfElements = $("#div").children().length; // Counting the number of existing divs return numberOfElements; } ...