Hovering over the Laravel Breeze dropdown will activate a dropdown feature

Recently, I've been working on a project with Laravel Breeze and have been utilizing some default components. The dropdown component used in the navigation bar caught my attention. By default, it requires a click for the menu to drop down below. However, I desire to tweak this component's behavior so that the menu appears on hover instead. Additionally, I want the option that clicking on the dropdown menu link leads to a different page altogether.

The specific dropdown component code snippet is as follows:

@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-blue-light'])

@php
switch ($align) {
    case 'left':
        $alignmentClasses = 'origin-top-left left-0';
        break;
    case 'top':
        $alignmentClasses = 'origin-top';
        break;
    case 'right':
    default:
        $alignmentClasses = 'origin-top-right right-0';
        break;
}

switch ($width) {
    case '48':
        $width = 'w-48';
        break;
}
@endphp

<div class="relative m-auto" x-data="{ open: false }" @click.away="open = false" @close.stop="open = false">
    <div @click="open = ! open">
        {{ $trigger }}
    </div>

    <div x-show="open"
            x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="transform opacity-0 scale-95"
            x-transition:enter-end="transform opacity-100 scale-100"
            x-transition:leave="transition ease-in duration-75"
            x-transition:leave-start="transform opacity-100 scale-100"
            x-transition:leave-end="transform opacity-0 scale-95"
            class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
            style="display: none;"
            @click="open = false">
        <div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
            {{ $content }}
        </div>
    </div>
</div>

Do you have any insights or suggestions on how I can modify this component to meet my requirements?

Answer №1

To create this functionality in Vue JS, you can utilize the @mouseover and @mouseleave directives to control the opening and closing of a menu. Below is an example of how the code can be structured:

<div class="relative m-auto" x-data="{ open: false }" @mouseover="open = true" @mouseleave="open = false">
    <div>
        {{ $trigger }}
    </div>

    <div x-show="open"
            x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="transform opacity-0 scale-95"
            x-transition:enter-end="transform opacity-100 scale-100"
            x-transition:leave="transition ease-in duration-75"
            x-transition:leave-start="transform opacity-100 scale-100"
            x-transition:leave-end="transform opacity-0 scale-95"
            class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
            style="display: none;"
            >
        <div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
            {{ $content }}
        </div>
    </div>
</div>

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

Implementing a class change to anchor elements when rearranging them

I have 4 divs and their corresponding anchor tags. The active class is dynamically added to anchors on scroll unless the order of the display elements changes. In that case, active classes are only applied to the sorted elements. I also sorted the nav anch ...

I'm having trouble accessing the vue.js website. Any ideas on what might be causing this issue?

While testing my SPA site frontend locally, everything was working perfectly. However, after configuring Apache and fixing bugs when trying to access the domain, the site does not show up as expected. Instead, I see a loading element in the center of the p ...

Switching the default port for a Vue.js application running in a Docker container

I am currently in the process of changing the default port for a Vue.js app running on docker. I have experimented with both examples provided in the official documentation, which can be found here. For instance, I have a Dockerfile using http-server: FR ...

Python: Convert a variable to an HTML file

This question may seem simple, but I've been searching for a solution without success for hours. I have an HTML file called "teste.html" I am using jinja 2 to make changes in my HTML. env = Environment(loader=FileSystemLoader('.')) template ...

What are some strategies for keeping the focus state on the parent item in a dropdown menu?

When I interact with the dropdown menu in my navigation bar, the color changes for the child items. How can I make sure that the parent item maintains the same colored background even after clicking elsewhere on the page? To better understand the issue, i ...

I'm looking for a method to retrieve the value of an option tag and then pass it to a helper within handlebars. Can someone

Currently, I am utilizing express and handlebars in my project. I have a specific view where I aim to display certain information based on the event when a client selects an option from a select tag. However, I have some queries regarding this: Is it fea ...

CSS animation for horizontal scrolling with sticky positioning is not functioning as intended

I've designed a creative way to achieve infinite horizontal scrolling using CSS animation, and my goal is to make the first element in the list stick in place. Everything works smoothly when I utilize the left property within the @keyframes. However, ...

Utilizing Props in the mounted hook of Vue.js 2

In my child components, I have data props that contain specific values. I need to access these values in the mounted function and set the select dropdown value accordingly. The code below demonstrates how I am using the vue-multiselect plugin to achieve th ...

When attempting to launch my JavaFX 2 application from an HTML page, it fails to execute

I recently downloaded the JavaFX 2 samples and encountered an issue when trying to run one of them from its HTML file. Specifically, I am referring to a JavaFX application called BrickBreaker, which consists of three files: BrickBreaker.jar, BrickBreaker.j ...

Is it possible to manipulate CSS on a webpage using javascript?

I have incorporated this piece of JavaScript to integrate a chat box onto my website: window.HFCHAT_CONFIG = { EMBED_TOKEN: "XXXXX", ACCESS_TOKEN: "XXXXX", HOST_URL: "https://happyfoxchat.com", ASSETS_URL: "https://XXXXX.cloudfront.ne ...

jQuery modal window extension

Currently, I am utilizing a jQuery popup plugin that opens a popup window using the anchor's href. For example: <a href="/some/site?hello=hi" class="popup">link</a> There could be an unlimited number of these on my page, each pointing to ...

The system encountered an issue regarding a missing dependency: Warning from chokidar (C:): Error: EBUSY: resource busy or locked, unable to access 'C:hiberfil.sys'

While working with Vue, I encountered an error after running npm run serve. Here is the screenshot of the error: Does anyone have suggestions on how to resolve this issue? ...

Restoring text boxes to their original styling

I've been working on a jQuery script that scans through form input elements and turns their border color to red if they are empty. When the submit button is pressed, it reassesses the elements; this time I'm trying to revert the textbox back to i ...

Maintain the image's aspect ratio by setting the width equal to the height when the height is

I am uncertain if achieving this purely with CSS is possible, but it would be ideal. I currently have an image: <img src="#" class="article-thumb"> CSS: .article-thumb { height: 55%; } Is there a way to set the width equal to the height? My g ...

Oops! Looks like there was a syntax error with the JSON data at position 1. This resulted in a 400

Having issues submitting form data in my Vue app with an express backend API. The endpoint works fine on postman but I keep getting errors like "SyntaxError: Unexpected token g in JSON at position 0" or "400: Bad Request." I've tried using JSON.parse ...

Adjust Vuetify v-alert property dynamically

Hey there, I'm facing an issue trying to change the type of a v-alert component within a method. Here's the snippet of my code: <v-alert type="{{alertType}}"> I'm a success alert. </v-alert> I attempted to bin ...

Controlling the page scroll when adding data using jQuery

I am encountering an issue with a webpage that displays around 20 pictures in separate divs stacked vertically. Below these 20 pictures, there is a "show more" button that, when clicked, loads another set of 20 pictures and appends them to the existing dat ...

Retrieve Element By Class Name in JavaScript

How can I modify the border color at the bottom of the .arrow_box:after? Javascript Solution document.getElementsByClassName("arrow_box:after")[0].style.borderBottomColor = "blue"; Despite trying this solution, it seems to be ineffective! For a closer ...

Step by step guide to building an exclusive form input field in HTML that allows only a single response

Is there a way in HTML to set up a text input or password input on a <form> that requires a specific value, such as "apples"? The form should only submit if the person entering their information types "apples" into the designated input field. ...

Utilizing property validation in your codebase

How can I set up my code to display a warning in the console if the value of the Prop is not a string? The player-name prop should always be a string. If this: <greet :player-name="5"></greet> contains a number, I want my code below to generat ...