Tips for postponing the opening of a CDK overlay

Utilizing the CDK Overlay, a "popover" is displayed when a user hovers over an item in a list. Currently, the popover opens upon triggering the mouseenter event.

Here is the code snippet:

//component.html
<mat-list-item *ngFor="let item of itemList" (mouseenter)="showItemDetail(item)">
    {{item.display}}
</mat-list-item>

//component.ts
showItemDetail(item: IItemDto, event: MouseEvent) {
        this.hideItemDetail(); // Closes any open overlays
        this.itemDetailOverlayRef = this.itemDetailOverlayService.open(item);
}

//itemDetailOverlayService.ts
open(item: IItemDto) {

        // Returns an OverlayRef (which is a PortalHost)

        const overlayRef = this.createOverlay(item);
        const dialogRef = new ItemDetailOverlayRef(overlayRef);
        // Create ComponentPortal that can be attached to a PortalHost
        const itemDetailPortal = new ComponentPortal(ItemDetailOverlayComponent);
        const componentInstance = this.attachDialogContainer(overlayRef, item, dialogRef);
        // Attach ComponentPortal to PortalHost
        return dialogRef;
}

private attachDialogContainer(overlayRef: OverlayRef, item: IItemDto, dialogRef: ItemDetailOverlayRef) {
        const injector = this.createInjector(item, dialogRef);
        const containerPortal = new ComponentPortal(ItemDetailOverlayComponent, null, injector);
        const containerRef: ComponentRef<ItemDetailOverlayComponent> = overlayRef.attach(containerPortal);
        return containerRef.instance;
}

It's important to note that the overlay relies on data from the list items.

Is there a way to delay the showItemDetail() function so that the overlay opens only after 2 seconds? Consider that only one popover should be open at a time.

Using setTimeout() won't suffice as multiple popovers may open if the user drags the mouse across the list of items.

Answer №1

Solved by displaying the layer immediately instead of waiting, and achieving a delayed effect through CSS animations/keyframes:

.box {
    animation: appear 2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
    }

    70% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

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

Retrieve the current element when the key is released and send it as a parameter to a different function

Imagine a scenario where my website contains textbox elements that are dynamically generated, each with the class 'mytxt'. <input type="text" class="mytxt" /> <input type="text" class="mytxt" /> <input type="text" class="mytxt" /& ...

Modify select option in Bootstrap Vue based on user input

I am facing a challenge in populating a Bootstrap-Vue form select with objects obtained via JSON. The JSON data comprises teacher information from various fields: [ { "id": 1, "name": "John", "surname": ...

Is there a way to ensure that a statement will not execute until the completion of a preceding function?

I am encountering an issue where the window.open function is being called too quickly, causing my other function not to finish and post in time within my onclick event. I attempted to address this by setting a timeout on the trackData() function, but it o ...

Organizing textual maps within a 2D array for rendering on an HTML5 Canvas

In my spare time, I am working on creating an HTML5 RPG game. The map is implemented using a <canvas> element with specific dimensions (512px width, 352px height | 16 tiles across, 11 tiles from top to bottom), and I'm wondering if there's ...

Error encountered in my application due to Node.js (Error [ERR_HTTP_HEADERS_SENT]: Unable to change headers once they have been sent to the client)

Experiencing an error message in my application when typing nodeJS. Please assist. , Encountering an error after sending the first POST request while running the app. const express = require('express') const Workout = require("../models/work ...

Should identifiers be avoided when using if/else conditions?

I'm questioning the use of a region id 5657 in my database for implementing if/else conditions. 1- Is it considered a bad practice to use an id for this purpose? 2- What would be the correct way to implement if/else conditions in this scenario? ctr ...

The error message thrown when running `ng test` states that the module '@angular-cli/plugins/karma' cannot be found

I have been exploring testing in my project and came across a suggestion to update the karma.conf.js file. The recommendation was to change angular-cli/plugins/karma to @angular-cli/plugins/karma, which involved adding the @ symbol before 'angular-cli ...

Using AngularJS filters to search through various fields of data

My goal is to conduct a search using multiple fields of a repeating pattern in combination. I am facing an issue where searching by query.$ model does not allow me to search from multiple fields. Specifically, I want to search for the number 1234 along wi ...

Express and Node.js working together

Recently, I've been encountering an issue with my POST function. Whenever I click on the log in button, a message pops up saying: Cannot POST /login I'm at a loss here and would greatly appreciate any help you can provide \(^-^\) B ...

How do I locate the specific page in angular.js where I need to make changes?

I have recently finished a project and now I am facing an issue that needs to be solved. In this project, there are 3 select boxes, each with different names. The first select box is named nameSelectBox162572640796915, the second one is named nameSelectBox ...

Can we iterate through custom variables in JavaScript?

Can the "iterate" function be implemented without using deprecated JavaScript features to loop through its own variables? (function () { var a = 1; var b = 2; var iterate = function () { // code to iterate over variables here }; }) ...

How to utilize dot notation in HTML to iterate through nested JSON in AngularJS?

I'm struggling with displaying nested objects loaded from a JSON file in Angular. I've seen examples of using dot notations in HTML to access nested data, but I'm new to Angular and can't seem to get it right. The JSON is valid, but I j ...

Caution: Refs cannot be assigned to function components

I'm currently using the latest version of Next.js to create my blog website, but I keep encountering an error when trying to implement a form. The error message reads as follows: Warning: Function components cannot be given refs. Attempts to access t ...

Having issues with Phonegap's getPhoto functionality

Even though the documentation here seems to be effective, I encountered an issue when implementing the code into my application. The getPhoto function returns 'content://media/external/images/media/16053' without loading the image into the img el ...

Converting a string to a date type within a dynamically generated mat-table

I am working on a mat-table that shows columns for Date, Before Time Period, and After Time Period. Here is the HTML code for it: <ng-container matColumnDef="{{ column }}" *ngFor="let column of columnsToDisplay" > ...

Stop fullscreen mode in Angular after initiating in fullscreen mode

Issue with exiting full screen on Angular when starting Chrome in full-screen mode. HTML: <hello name="{{ name }}"></hello> <a href="https://angular-go-full-screen-f11-key.stackblitz.io" target="_blank" style=& ...

Ways to manually activate animation within the component

How can I trigger an animation in Angular 9 animations directly from the component itself? It seems like manual triggering in the component is necessary as it needs to keep track of the graph creation state, rather than relying on a template expression w ...

The type 'string' cannot be assigned to type 'ImageSourcePropType'

Context Attempting to utilize a SVG component in React Native with the xlinkHref property within an Image tag. The SVG file was converted into a React Native Component (TSX) using the tool provided at . While simple SVG icons have been successfully used be ...

How come JSON.parse is altering the data within nested arrays?

In my journey to master Angular 2, I decided to challenge myself by creating a Connect Four game using Angular CLI back when it was still utilizing SystemJS. Now, with the switch to the new Webpack-based CLI, I am encountering a peculiar issue... The fun ...

carousel initialization failed due to materialization error

I am experiencing a peculiar issue with the carousel feature on a website built using MaterializeCSS. Sometimes it functions correctly, but other times I encounter the following error: jQuery.Deferred exception: c is undefined s@https://cdnjs.cloudflare.c ...