Setting the background color for the active nested sub-group header

Request in Plain Language

I'm working with a nested v-list that has the following structure:

https://i.sstatic.net/6t2ck.png

The aim is to have the headers "BusinessUnitA" and "TaskY" highlighted (with some background color) when active. Currently, they only highlight on hover. "Task Y" appears in red font when active, but I need it to be highlighted.

Coded Layout

This snippet shows the corresponding HTML template:

<template>
  <v-container>
    <v-list dense>
      <v-list-group
          v-for="businessUnit in businessUnits"
          :key="businessUnit.businessUnitName"
          v-model="businessUnit.active"
          no-action
      >
        <template v-slot:activator>
          <v-list-item>
          <v-list-item-content >
            <v-list-item-title   v-text="businessUnit.businessUnitName"></v-list-item-title>
          </v-list-item-content>
          </v-list-item>
        </template>
        <v-list-group
            v-for="item in businessUnit.tasks"
            :key="item.taskName"
            :value="true"
            no-action
            sub-group
        >
          <template v-slot:activator>
            <v-list-item-content>
              <v-list-item-title v-text="item.taskName"></v-list-item-title>
            </v-list-item-content>
          </template>
          <v-list-item-group>
            <v-list-item>
              <v-list-item-content>
                <v-row>
                  <v-col
                      class="d-flex"
                      cols="6"
                      sm="6"
                  >
                    <v-list-item-avatar>
                      <v-img :src='item.responsible.avatar'></v-img>
                    </v-list-item-avatar>

...

</template>

And here's the scripting portion:

<script>
export default {
  name: "ZklListNew",
  data: () => ({
        businessUnits: [
          {
            businessUnitName: 'BusinessUnit A',
            municipality: 'Cityname',
            tasks:
                [
                  {
                    taskName: 'Task Y',
                    responsible: {
                      name: 'Max Müller',
                      email: 'max.mü<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9a5a5acbb89bdacbabde7a4a8a0a5e7aaa1">[email protected]</a>',
                      phone: '+44 77 123 45 67',
                      avatar: require("@/assets/avatar-placeholder.gif"),
                    },
                    deputy: {
                      name: 'Katharina Knüller',
                      email: 'katharina.knü<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="452929203705312036316b28242c296b262d">[email protected]</a>',
                      phone: '+44 77 123 45 67',
                      avatar: require("@/assets/avatar-placeholder.gif"),
                    }
                  }]
          },
        ]
      }
  ),
}
</script>

Troubleshooting Steps Taken

I attempted to use the active class as recommended by the documentation (https://vuetifyjs.com/en/components/list-item-groups/#examples) in this fashion:

Template excerpt:

...

<template v-slot:activator>
  <v-list-item>
  <v-list-item-content >
    <v-list-item-title  active-class="border" v-text="businessUnit.businessUnitName"></v-list-item-title>
  </v-list-item-content>
  </v-list-item>
</template>

...

<template v-slot:activator>
            <v-list-item-content>
              <v-list-item-title active-class="border" v-text="item.taskName"></v-list-item-title>
            </v-list-item-content>
          </template>
...

As for styling:

<style scoped>
.border {
  background-color: red;
}
</style>

I also experimented with adding custom classes like

class="v-list-group__header"
, and applied styles to them, but to no avail.

Apologies for the lengthy query. I aim for clarity while providing all necessary details.

Answer №1

Almost there! To address your query accurately, simply include the active-class prop in your v-list-group. This will apply the specified class only when the item is active. Ensure that you add this to each list group as needed.

<v-list-group
  v-for="businessUnit in businessUnits"
  :key="businessUnit.businessUnitName"
  v-model="businessUnit.active"
  no-action
  active-class="grey lighten-2"
>

For more details on the active-class feature, refer to the documentation 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

Steps for showing an alert notification when the form field is empty

Within my script, there is a Bootstrap form where I am facing an issue. If the user fails to select a language and leaves the value blank or as "Select Language," I want to display an alert message prompting them to choose a language before proceeding to t ...

What are some effective strategies for preventing CSS duplication?

What is the best way to prevent repeating CSS code like this: div#logo div:nth-child(1) div { width: 30%; height: 30%; background-color: white; } div#logo div:nth-child(3) div { width: 30%; height: 30%; background-color: white; ...

Issue: Animation not triggered on exit by React-transition-group Transition

I am aiming to create a unique animation where an icon spins 90 degrees to become flat and then seamlessly transitions into another icon, simulating a coin-spin effect. The desired effect is for the icons to spin both on enter and exit, although there may ...

Create three div elements that mimic the appearance and functionality of a video to the fullest extent possible

Dear all, I am currently working on a project where I aim to achieve a layout similar to the one featured in this video. The goal is to have 3 divs aligned horizontally, with an image div positioned at the center while the other two divs contain random let ...

Responsive flex elements in a single line

I am facing a challenge with five divs that I want to display inline and make them responsive. The issue is that when the window size changes, they end up getting squished together instead of breaking into a new row as desired. I have tried various methods ...

Images are not loading properly on the website when viewed on an iPad

As I work on my website with a parallax effect, I recently came across an issue: images not displaying on iPod devices. Unfortunately, since I don't have access to an iPod, I am unable to verify this myself. Can anyone explain why the main pictures ar ...

At long last, I successfully implemented collapsible styling for XML-generated data, yet I am struggling to get the data

After much experimentation, I have successfully applied JQuery Mobile collapsible styling to data retrieved from an XML file using this code/method. However, I am facing an issue with getting all JQuery styling to work properly - particularly the icon do ...

Tips for aligning 2 divs in the same position?

I am working on a slider feature that includes both videos and pictures. I need to ensure that the videos are hidden when the device width exceeds 600px. Here is the HTML code snippet: <video class="player__video" width="506" height="506" muted preloa ...

Expanding and collapsing a div using jQuery when an image is clicked

I have a query that spans across two areas - CSS styling and JQuery functionality. The primary concern I have is related to my code snippet below. When the user clicks on the circular profile image, ideally, the "profiledrop" div should become visible. ...

Display a particular div upon clicking a specific link, while concealing the other divs

As a beginner in the world of jQuery and coding, I'm encountering some difficulties that I need help with. My goal is to have the 'Vlogging' link activated and show 'Details 1' when the page loads. Then, upon clicking on either &a ...

Can the data cells of columns be dynamically adjusted to align them on a single vertical line?

For some time now, I have been grappling with a CSS issue. I am working with a table that has 3 columns displaying departures, times, and situational text for scenarios like delays or cancellations. However, as evident from the images, the alignment of th ...

Unable to make the Show/Hide Loading GIF function work as intended

Could someone please help me with my code? I'm trying to display a loading GIF image while waiting for an ajax request to complete. When the button is pressed, I want the loader to be shown until the data is returned from the server. I would greatly ...

The fundamental principle of starting with mobile design in Bootstrap

I'm struggling to understand the concept of "mobile first default behavior" in Bootstrap 3. If there is no breakpoint at 480px, how can Extra small devices be the default? I get that it applies to font sizes, but what about the grid system? How can I ...

Using CSS :active can prevent the click event from firing

I've designed a navigation menu that triggers a jquery dialog box to open when a link is clicked. My CSS styling for the links includes: .navigationLinkButton:active { background:rgb(200,200,200); } To attach the dialog box, I simply use: $("#l ...

What might be causing the image links to malfunction on the server while functioning normally when offline?

Recently, I've been working on a website and after successfully testing it offline, I decided to put it online. However, I've run into an issue where some images are not showing up. What's even stranger is that the images that are appearing ...

I am unable to retrieve information from Firebase in Vue

Currently, I am following a tutorial on YouTube to enhance my knowledge about storing data in Firebase and then utilizing it in a Vue application. (You can watch the tutorial at this link: https://www.youtube.com/watch?v=Htt8AKeF1Kw, you will encounter the ...

What is the best way to have two text-divs overlapping within a single wrapper div?

In a wrapper div, there are two inner divs with different text. The goal is to change the text on hover and position the second text div exactly where the first text div is. .wrapper { background: red; width: max-content; padding: 20px; } .text1 ...

Creating a progress bar that includes hyperlinks: A step-by-step guide

Currently, I am in the process of developing an application form that consists of 9 pages of questions. Initially, I had implemented a progress bar which indicated completion by filling up 1/9 for each page completed. However, I have been informed that thi ...

The Unknown Component Dilemma in Vue.js

In my parent component, I import 2-3 child components and toggle their visibility based on button clicks. Each child component includes Back and Next buttons, which control the display of different components in various scenarios. Here's a snippet fro ...

Utilizing SVG images as interactive elements without embedding them directly into the HTML code

I am facing a challenge with incorporating button images saved as svgs into my HTML site. These images are intricate, so I prefer to have them stored separately as .svg files rather than directly within the HTML file. Additionally, the buttons are circular ...