Adding a component to a grid row with a click action

I have a grid of items and I want to display another component that takes up the full width below the clicked item when it's selected.

Here is an illustration of what I'm trying to accomplish: https://i.sstatic.net/5XIvf.png

Within my button-list-component, there is a button-component that displays the items using ngFor. When an item is clicked, the size-selection-component is shown using ngIf.

The issue I'm facing is that if the size-selection-component is within the button-list-component, it appends at the end of the grid. Alternatively, if placed in the button-component, it only takes the width of the column containing the clicked item.

If I use position: absolute to make it the width of the container, the following items won't flow down properly.

Below is a snippet of my code:

button-list

<div class="wrapper">
  <div class="container">
    <app-button *ngFor="let button of buttons;" [button]="button" (buttonClicked)="onButtonClicked($event)">
    </app-button>
  </div>
</div>
.container {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(250rem, 1fr));
  grid-gap: 10rem;
  place-items: start center;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 10rem;
}

button

<div class="product">
    <div class="product-col">
        <h2 class="product_title" (click)="onButtonClicked()">{{button.Caption}}</h2>
        <img class="product_img" [src]="picture" alt="" (click)="onButtonClicked()">
        <span class="product_price" *ngIf="button.Price && button.Price != '0'">{{button.Price / 100 | currency}}</span>
    </div>
</div>

<app-size-selection-button-list *ngIf="isSizeSelectionOpen"></app-size-selection-button-list>

I'm looking for suggestions on how to achieve this layout effectively, whether through CSS solutions or other methods for inserting components into the grid seamlessly.

Thank you

Answer №1

You have the option to create and hide the div instead of appending it. When a user hovers over the item div, you can display it and set the innerHTML of its child tag to your desired content. Here's an example:

<body>
    <p onmouseover="show();"></p>AA</p>
    <div style="width:100%">
        <div style="width:33%">
            <p>Name</p>
        </div>
        <div style="width:33%">
            <p>Name</p>
        </div>
        <div style="width:33%">
            <p>Name</p>
        </div>
    </div>
    <div id="blah" style="display:none">
        <!-- content goes here -->
    </div>
<script>
    function show() {
        var b=document.getElementById("blah");
        b.style.display="block";
        // Update innerHTML of elements inside the blah div as needed
    }
</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

What could be causing the error? And is there a way to successfully append the child div to the parent div?

Here is the error message that I am encountering: Uncaught TypeError: Cannot read property 'appendChild' of null at HTMLButtonElement.<anonymous> Error is located at app.js on line 7 const flexContainer = document.querySelector(&apo ...

Custom field validation in Angular 2 forms based on Observable API responses

I am currently working on an Angular 2 Model-driven form where I need to implement custom validation on a text field to check if the entered name is unique by calling an API. Despite trying out various examples from different online sources, none of them s ...

What is the best way to adjust a div's size according to the device's screen dimensions?

I'm in the process of developing a web app that will be used on iOS devices, specifically targeting both iPhone 4 and iPhone 5. During my development phase using an iPhone 5 device, everything seemed to fit perfectly and work seamlessly. However, when ...

Error in Angular Protractor e2e test due to iteration function on mat-radio-group innerText

clickOnQuestionsOption(optionName) { const radioButtonList = $$('mat-radio-group > mat-radio-button'); const selected_btn = radioButtonList.filter(elem => { return elem.getText().then(text => { console.log(tex ...

Updating a value in an array in Angular using the same ID

I have an array of buildings that looks like this: const buildings = [ { id: 111, status: false, image: 'Test1' }, { id: 334, status: true, image: 'Test4' }, { id: 243, status: false, image: 'Test7' }, { id: 654, stat ...

How do I integrate a button into my grey navigation bar using tailwindcss in REACT?

Is it possible to integrate the - button into the gray bar? I am encountering an issue where my blue button extends beyond the borders of the gray bar in the image provided. export default function App() { ... return ( <div className="text-md fon ...

An error has occurred in the tipo-struttura component file in an Angular application connected with a Spring backend and SQL database. The error message indicates that there is a TypeError where the

Working on my project that combines Spring, Angular, and MYSQL, I encountered a challenge of managing three interconnected lists. The third list depends on the second one, which in turn relies on user choices made from the first list. While attempting to l ...

I require varying numbers of columns on each row based on the breakpoint in Bootstrap4

After realizing it was easier than expected, I simply consolidated all columns into one row and the responsiveness now works perfectly. Thank you to everyone who helped. https://i.sstatic.net/4Sx41.png I am utilizing Bootstrap 4 grid system to structure 3 ...

In HTML, favoring the use of "//domain.com" over "https://domain.com" or "http://domain.com" is recommended for greater flexibility and compatibility

Related Questions: Changing all links to // Network-Path Reference URI / Scheme relative URLs I have noticed some websites using the following format: background:url(//cdn.domain.com/images/bg-normal.png) They utilize "//", which the browser aut ...

Print the page number using HTML and PHP

Is there a way to center page numbers in HTML? I have the code below that echoes the numbers, but they always appear on the left side of the page. I tried wrapping them in a div to center them, which worked, but then each number is enclosed in its own d ...

Make sure all of the inner tags are properly contained within their respective containers

In my explanatory bubble, I aim to include text within the explain-header div as a container for my explanations: /*Explain Bubble*/ .explain-container { position: relative; overflow: hidden; max-width: 70vw; max-height: 50vh; background-c ...

Editify Angular Text:Note: The name 'Edit

I am currently working on a coding project that involves allowing a user to click a button on the screen and view a paragraph that they can edit. I removed the readonly part of my code, but the paragraph is still not editable. How can I make it so that the ...

css - aligning text below another text in the center

Looking to style a text in a specific color with a message about another text below it? Want the text centered but not sure how to position it correctly? margin: 0px auto; If this code isn't delivering the desired result and is positioning your text ...

Once you address a block using jQuery

$(function(){ $(window).scroll(function () { var scrollVal = $(this).scrollTop(); var adscrtop =$(".header").offset().top // 在 RWD 767以下不作動 if(window.screen.width>767){ if(sc ...

Difficulty accessing files with Angular deployment in Nginx through Docker

Recently, I delved into the world of Docker and Nginx in an attempt to deploy my angular application. Unfortunately, I encountered a perplexing issue. Upon executing the command: npm run build, I noticed that my index.html contained script references as f ...

How to position an empty Div next to images

I am currently working on a project to familiarize myself with Japanese Hiagana. I plan to incorporate more images and eventually sound into the post. To reduce the number of images used, I attempted to replace empty .pngs with a div element. However, I am ...

How to ensure the height of an image in a Bootstrap flex row matches the

I just updated to the latest Bootstrap 5.0 beta version and I'm working with this html code snippet: <div> <div class="d-flex flex-row"> <img src="img/funny.png" alt=""> ...

Loop through an entity to identify the corresponding active days for each id

Review the following array of objects: const resource = [ { id: 'tony', shiftday: [ {active: '1', code: 'Sun'}, {active: '1', code: 'Mon'}, {active: & ...

What is the best way to divide a pair of words onto two lines individually?

Looking for a way to break the word 'Mon 24' into separate lines like this: Mon 24 I attempted using word-break: break-all without success. Check out my code example here: https://codepen.io/bbk_khadka/pen/zbVLEp ...

Angular navigation is inconsistent in its functionality

Currently, my Angular project consists of four components: home, portfolio, contact, and about. While I can navigate from the home page to any other component using the nav-bar, I am restricted to navigating only back to the home page when on any other pag ...