DaisyUI nested collapse components featuring a dropdown menu

Here's an update following the discussion in this thread. I've implemented the solution suggested there into my Vue component, modified the collapse section, and turned it into a nested collapse with multiple collapse elements nested inside.

The current issue I'm facing is that when I apply !overflow-visible to the main collapse element to override its behavior, the child elements within it start overflowing even when the collapse is closed.

How can I address this issue? I attempted to add overflow-hidden to the child components of the collapse, but due to inheritance, the overflow-hidden rule doesn't have any effect. Additionally, despite setting a z-index value of 99 to the collapse containing the dropdown, it fails to display above other elements as expected.

<template>
  <div
    v-for="index in 3"
    tabindex="0"
    class="collapse !overflow-visible collapse-plus z-0 rounded-lg border border-base-content bg-base-100 shadow-md md:w-[48.75%]"
    :class="collapse ? 'collapse-open' : 'collapse-close'"
  >
    <div
      class="collapse-title !overflow-hidden flex items-center text-lg font-medium"
      :class="collapse ? 'bg-primary' : 'bg-base-100'"
      @click="OnClick"
    >
      <div
        class="mr-3 grid h-[58px] !overflow-hidden w-[62px] place-content-center rounded-lg"
        :class="collapse ? 'bg-base-100' : 'bg-primary'"
      ></div>
      <div
        class="flex flex-col gap-1"
        :class="collapse ? 'text-base-100' : 'text-primary'"
      >
        Test
        <div class="badge badge-success rounded-[4px]">Active</div>
      </div>
    </div>
    <div class="collapse-content bg-base-200 !p-0 text-accent">
      <div
        tabindex="0"
        class="collapse collapse-open border border-base-300 bg-red-200 !overflow-visible"
      >
        <div class="collapse-title text-xl font-medium">
          I have collapse-open class
        </div>
        <div class="collapse-content !overflow-visible">
          <h2>HELLLERGLERL</h2>
          <h2>HELLLERGLERL</h2>
          <h2>HELLLERGLERL</h2>
          <h2>HELLLERGLERL</h2>
          <h2>HELLLERGLERL</h2>
          <h2>HELLLERGLERL</h2>
          <details class="dropdown dropdown-end z-[99]">
            <summary class="m-1 btn">open or close</summary>
            <ul
              class="p-2 shadow menu dropdown-content z-[98] bg-base-100 rounded-box w-52"
            >
              <li><a>Item 1</a></li>
              <li><a>Item 2</a></li>
              <li><a>Item 1</a></li>
              <li><a>Item 2</a></li>
              <li><a>Item 1</a></li>

              <li><a>Item 2</a></li>
            </ul>

            <div
              tabindex="0"
              class="collapse collapse-open border border-base-300 bg-blue-200 !overflow-visible"
            >
              <div class="collapse-title text-xl font-medium">
                I have collapse-open class
              </div>
              <div class="collapse-content">
                <details class="dropdown">
                  <summary class="m-1 btn">open or close</summary>
                  <ul
                    class="p-2 shadow menu dropdown-content z-[99] bg-base-100 rounded-box w-52"
                  >
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                    <li><a>Item 1</a></li>
                    <li><a>Item 2</a></li>
                  </ul>
                </details>
              </div>
            </div>
          </details>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
const collapse = ref(false);

function OnClick() {
  collapse.value = !collapse.value;
}
</script>

Answer №1

To improve the user experience, you might want to utilize the built-in <Teleport> feature in Vue.js for rendering the drop-down menu outside of collapsible elements. This eliminates the need to manage overflow: visible/hidden properties. However, keep in mind that manual positioning of the dropdowns will be required since they won't be contained within the same parent as the dropdown buttons.

Below is a simple example to illustrate this approach:

const { createApp, ref } = Vue;

const dropdown = {
  setup() {
    const open = ref(false);
    const button = ref();
    const style = ref({});
    
    const toggle = () => {
      open.value = !open.value;
      if (open.value) {
        const rect = button.value.getBoundingClientRect();
        
        style.value.top = `${rect.top + window.scrollY}px`;
        style.value.left = `${rect.left + window.scrollX + rect.width}px`;
      }
    };
    
    return { open, toggle, button, style };
  },
  template: '#dropdown',
};

createApp({
  components: {
    dropdown,
  },
  setup() {
    const collapse = ref(false);

    function OnClick() {
      collapse.value = !collapse.value;
    }
    
    return { collapse, OnClick };
  }
}).mount('#app')
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.13/vue.global.prod.min.js" integrity="sha512-dJsT2VK9KxehzZYzxzUELznI6velu2pAOwpkL5jj4TQQhTNGXZUMup7aLqgqNwVPSUF/Ntcdfla3BEcfC7zwCw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8e8b8399939f83aadec4dec4d8d9">[email protected]</a>/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com/3.4.0"></script>

<div id="app">
...

<template id="dropdown">
...
</template>

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

Whenever I use Vue JS, I notice that it displays [Object object] on console.log and returns Undefined when

Currently, I'm developing Vue.JS code to showcase data fetched by PHP from a server. The PHP sends a JSON object to the Vue for display. Below is my existing code snippet: axiosPost(); } function axiosPost() { axios.post( './Conver ...

Using bootstrap's center-block class, you can easily center

I'm attempting to center the content of a form. <div class="login-container"> <div class="center-block"> <form action="/joinChart" method="get"> <input name="username" id="username" type="text"><br><br> ...

Issue when attempting to update the background image using d3.js in browsers other than Firefox

I am experiencing a strange error that is puzzling to me. What I have done is placed a background image (SVG file) in a div using CSS. This SVG is used to create a Sprite animation, which is functioning correctly. .runner { background: url("0804_ ...

Having trouble getting CSS and Bootstrap to work in Laravel 5.8. Any suggestions on how to resolve this issue?

Facing a major issue while using Laravel 5.8 - unable to read CSS and Bootstrap. 1. Tried to run rm storage in order to execute php artisan storage:link, but it didn't work as expected. 2. After running php artisan serve failed, I switched to chdir( ...

The arrows on the Slick Slider appear cropped on ios devices like the iphone 8, however, they display perfectly when tested on Chrome and Firefox

I am currently facing an issue with my slick slider setup at https://www.labtag.com/shop/product/clear-cryogenic-labels-for-frozen-vials-1-75-x-1-aha-224/. It is configured for 4 slides on desktop and 2 slides on mobile devices (768px breakpoint). The pr ...

The combination of two colors in a hard background fails to create an appealing aesthetic

Seeking assistance with an issue I encountered while trying to create a two-color background. Below is the code snippet: body, html { height: 100%; width: 100%; background: #0000ff; background: linear-gradient(180deg, #ff0000 50%, #0000f ...

Log out the user automatically upon token invalidation

My website is a Single Page Application developed with Vue.js. Whenever a user logs in through the API, their token gets stored in local storage. I am looking to implement a universal solution that will automatically log out the user and display a prompt ...

Designing a Scrollable tbody Element while Preserving the Integrity of the tbody Columns

Currently, I am attempting to implement a scrollable tbody in order to run a React package smoothly. The challenge lies in achieving a scrollable tbody without having to resort to using display: block on the tbody element. Unfortunately, this solution dis ...

Positioning a div with a set size to the right while allowing a div with a variable width to the left

Even though I achieved the desired outcome in this example (http://jsfiddle.net/jcx3X/40/), I am intrigued by the reasons why this other scenario (http://jsfiddle.net/jcx3X/41/) does not work. What is the significance of the div being floated first in th ...

A guide on layering .ogg video with .png image using HTML5 and CSS3

I am having difficulty achieving the desired effect, even when using z-index and position:absolute. My goal is to overlay a .png image on top of a video, while still allowing the transparent parts of the .png file to reveal the video playing in the backg ...

The page query functionality seems to be malfunctioning when implemented within a Gridsome component

While using <page-query> within the index works fine, I encounter an error of "edges undefined" when I try to use it inside a component. Can someone provide assistance with this issue? ...

the else/if statement executes only on the first run

In my current code, when the user inputs a color that matches any of the colors in the array, it will add that color class to the main div. The issue I'm facing is that my else-if statements only run once. If you input the same color again, it won&ap ...

Can CSS be altered dynamically in Laravel blade?

Is there a way to dynamically change CSS? I am trying to set the class=sheet padding-top: 28mm; when the size of $anArray is less than 30. If the array has more than 30 elements then apply padding-top: 28 * 2 mm;. Finally, if the array exceeds 60, use pad ...

Utilizing CSS classes to namespace pseudo-selectors

After attempting to search on Google, I am struggling to find the right keywords. I'm trying to apply a pseudo-selector only to a specific class. In this scenario, if we remove the specified class, the last Hi should appear in blue. However, my expe ...

Applying styled text to a Node.js chat application

I developed a chat application using node.js which allows users to enter a username and send messages. The messages are displayed in a <ul> format showing "username: message". I was looking for a way to make the username appear bold and in blue color ...

VUE3 - Trigger Bootstrap Modal with Image Click on Multiple Pages/Components Without the Use of JQuery

Attempting to integrate VUE3 and Bootstrap for the purpose of opening a Modal upon clicking one of two images. I have organized my project into 3 Components: Left DIV (Image) Right DIV (Image) Modal While successful in operating this feature on a Singlep ...

Navigating through VueJS: Understanding the Routing Concept

Here's a query that might seem silly, especially since I'm unsure if I'm working with VueJS or VueJS 2.0. I'm attempting to implement basic routing functionality where I can access the parameters or path from the URL. For instance **** ...

Header with a stable background image that adjusts responsively

While attempting to convert a PSD to HTML, I encountered a small issue. Please refer to the image below: https://i.sstatic.net/5KoIV.jpg As indicated by the red arrow, there is a blue background image in the header of the template! How can I add this bac ...

What is the best way to update image CSS following a rotation using JavaScript?

Discover a neat CSS trick for always centering an image in a div, regardless of its size or aspect ratio. <style> .img_wrap { padding-bottom: 56.25%; width: 100%; position: relative; overflow: hidden; } #imgpreview { display: bl ...

Placing one element beside another element

I am facing an issue with my layout where I have a list taking up 100% of the height and next to it, I am attempting to place an image box. Here is the fiddle link for reference: https://jsfiddle.net/wrdvkgyj/ Even after setting my image container to inl ...