`How can I customize the appearance of individual selected <v-list-item> across various sub-groups?`

As a newcomer to Vuetify and Vue in general, I am struggling to solve a specific issue. I need to create multiple sub-groups where only one option can be selected within each "parent" list.

Consider an array of cats:

options:["Crookshanks", "Garfield", "Leeroy"]

These cats are divided into 2 sub-groups (see pseudo code below)

subgroup 1
  Crookshanks
  Garfield
subgroup 2
  Leeroy

I have successfully managed to display the text content of the selected item, but now I want to implement some visual changes such as highlighting or adding a check mark to indicate the selection. This should be a toggle effect where only one item can be selected at a time, clearing the effect on the previously selected item when a new one is chosen. Unfortunately, manually setting an active class did not work for me (I suspect it's not supported for sub-groups):

<v-list-item 
active-class="selectedCat">

If you'd like to experiment with this concept, check out this Codepen link. Your assistance would be greatly appreciated!

Answer №1

To effectively highlight the selected element, utilize the v-list-item-group component. Consider the following example:

<template>
  <div id="app">
    <div>
      fictionalSelected = {{ fictionalSelected }}
    </div>
    <div>
      realSelected = {{ realSelected }}
    </div>

    <v-app id="inspire">
      <v-card class="ma-1" width="700">
        <v-list>
          <v-list-group prepend-icon="pets">
            <template v-slot:activator>
              <v-list-item-title>CATS</v-list-item-title>
            </template>
            <v-list-group no-action sub-group>
              <template v-slot:activator>
                <v-list-item-content>
                  <v-list-item-title>Fictional</v-list-item-title>
                </v-list-item-content>
              </template>

              <v-list-item-group v-model="fictionalSelected" @change="fictionalChanged">
                <v-list-item v-for="cat in fictionals">
                  <v-list-item-title>{{ cat }}</v-list-item-title>
                </v-list-item>
              </v-list-item-group>
            </v-list-group>

            <v-list-group sub-group no-action>
              <template v-slot:activator>
                <v-list-item-content>
                  <v-list-item-title>Real</v-list-item-title>
                </v-list-item-content>
              </template>
              <v-list-item-group v-model="realSelected" @change="realChanged">
                <v-list-item v-for="cat in reals">
                  <v-list-item-title>{{ cat }}</v-list-item-title>
                </v-list-item>
              </v-list-item-group>
            </v-list-group>
          </v-list-group>
        </v-list>
      </v-card>
    </v-app>
  </div>
</template>

<script>
export default {
  name: 'app',
  data: () => ({
    fictionals: ['Crookshanks', 'Garfield'],
    fictionalSelected: null,
    reals: ['Leeroy'],
    realSelected: null,
  }),
  methods: {
    fictionalChanged() {
      console.log('fictionalChanged');
      this.realSelected = null;
    },
    realChanged() {
      console.log('realChanged');
      this.fictionalSelected = null;
    },
  },
};
</script>

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

Tips for eliminating the left and bottom border in a React chart using Chart.js 2

Is there a way to eliminate the left and bottom borders as shown in the image? ...

Webpack Progress Vue Plugin

I'm currently in the process of learning Vue, but I'm struggling with a specific error that I can't seem to solve despite looking through the documentation and other resources. Any tips or guidance would be greatly appreciated... The projec ...

Is there a way in WebStorm to create a "virtual" folder for conveniently organizing and hiding config files, or perhaps a feature that allows for easily toggling visibility of certain files?

I have a strong dislike for having all my configuration files cluttering up the root directory. These files are usually set up at the beginning of a project and rarely need to be changed. While I can hide them in WebStorm, it becomes a hassle to unhide the ...

Guide on positioning a span element to the left using the margin auto property in CSS for Angular 4

Having trouble with moving numbers highlighted to the left with names in CSS. I've tried using flex direction and margin auto but can't achieve the desired result. Here is my HTML code: <section class="favorites"> <div class="category" ...

Having issues with ng-repeat not displaying any content

Let me describe the current situation I am facing: app.controller('ResourceController', function($scope, $sce){ var resourceData; $scope.data = ''; $scope.loadResources = function(){ $.get('con ...

Creating PropTypes from TypeScript

Currently in my React project, I am utilizing TypeScript along with PropTypes to ensure type checking and validation of props. It feels redundant to write types for both TypeScript and PropTypes, especially when defining components like ListingsList: inte ...

Avoid invoking a TypeScript class like a regular function - _classCallCheck prevention

I am currently developing a TypeScript library that needs to be compatible with all versions of JavaScript. I have noticed that when calling a class in TS without using new, it does not compile properly, which is expected. In ES6/Babel, a class automatica ...

Using Javascript to retrieve form data from a separate file

I am struggling with my HTML and JavaScript files to collect data. Despite my efforts, the function is not executing properly. Below is the code I have been working on: HTML File : <form class="form-newsletter"> <div class="form-group"> ...

Diverse Browser Outcomes with jQuery CSS

Currently, I am in the process of developing an app that utilizes percentages as offset positions for ease of calculation. For a visual example, you can visit this link: http://jsfiddle.net/WeC9q/1/embedded/result/ Although the zooming feature functions ...

Binding textarea data in Angular is a powerful feature that allows

I am looking to display the content from a textarea on the page in real time, but I am struggling to get the line breaks to show up. Here is my current code snippet: app.component.html <div class="ui center aligned grid">{{Form.value.address}}< ...

Express & React: Be cautious of client checksum and style while server-side rendering

Recently delving into the world of React server side rendering, I'm currently working on a small demo utilizing technologies such as React, Redux, React Router, and Material UI. The main issue I'm encountering is the following warning. I am uncer ...

How can you locate the position of identified text on a webpage to accurately place the mouse cursor there?

When browsing a webpage in my web browser (preferably Firefox), I have the ability to search for a specific text "abc" using ctrl+f. Once found, I need to move my mouse cursor to another relative position on the page and click. Unfortunately, the necessar ...

What is the origin of function parameters in javascript?

I have implemented the following code: handleOwnerMode = ownerChecked => { this.setState(prev => ({ ownerChecked, showOwner: !prev.showOwner})) // this.setState(prev => ({ ownerChecked: !prev.ownerChecked, showOwner: !prev.showOwner ...

What is the best way to transfer a value from a function to a variable in VueJs?

Currently, I am receiving the base64 of an image URL. When passing the getImage function to the savepdf function and attempting to store the callback function's base64_data in a variable, an error is thrown: An error occurs - Cannot set property &a ...

Processing XML Files Using Nodejs

Apologies for the rookie question, but I'm feeling a bit confused... I'm attempting to pull "objects" from an XML file so that I can modify and incorporate them into a database. I attempted using xml2js and now have a JavaScript object, but I&ap ...

Exploring X3DOM nodes using d3.js

I'm attempting to loop through X3DOM nodes in D3.js, but I'm encountering an issue. Check out the code snippet below: var disktransform = scene.selectAll('.disktransform'); var shape = disktransform .datum(slices ...

Top choices for creating animations using THREE.JS

Which animations work best in three.js? Are you using additional libraries like tween.js or something else for texture animations, moving objects, and showing/hiding objects? Thank you. ...

Retrieving text from a draggable div using jQuery

I have a draggable div that I can move over another element with the class .outerDiv which contains text content. Is there a way for me to retrieve the text from .outerDiv that overlaps with the draggable div? $(".outerDiv .isStore").draggable({ contain ...

At what point is the ajax call considered fully executed?

Whenever a client makes an AJAX call, they upload data to the server (HTTP request) and then receive data from the server (HTTP Response). Once the clients have received all the data, the AJAX request is considered successful, and the success callback func ...

When removing an item using its key, the vue component does not automatically refresh

I'm attempting to remove an object by its key and expecting the component to update accordingly using Vuex. Here is my current approach: The structure of my objects is as follows: 115:Object 116:Object I have the keys (115, 116) and I am t ...