1

I'm creating a data tree where the child components are just new instances of the parent. When I hover over the folder name in the parent, I show edit and delete buttons. I want that same behavior when my folder is expanded to show the child components, but the hover does not work. I have tried disabling the view encapsulation and also the /deep/ approach in the css file, but I couldn't get either to work. I've also tried binding a css class and then passing it to the new instance, but again that didn't work.

yes buttons

no buttons

library-tree.html (parent to Library)

<div id="scrollbar-style">
    <div *ngFor="let media of libraries">   
        <library 
                [media]="media">
        </library>          
    </div>      
</div>

library.html (child of Library Tree)

<h4 class="category-name>{{media.name}}</h4> //hover here

<div class="edit-delete-btns"> //buttons that show on hover at the top level, but not in child Library components
    <button name="media.id" (click)="onCategoryNameEdit()"></button>
    <button name="media.id" (click)="onCategoryDelete(media.id)"></button>
</div>

<div *ngIf="libraryVisible">
    <ul *ngIf="media.category">
        <li *ngFor="let category of media.category">
            <library [media]="category" [ngClass]="libraryCompClass" [libraryCompClass]="libraryComp"></library>
        </li>
    </ul>
</div>

Library.ts

import { Component, EventEmitter, HostListener, Input, OnInit, Output } from '@angular/core';
import { Media } from '../../../shared/models/media';

export class LibraryComponent implements OnInit {

  @Input() libraryCompClass: string;
  @Input() media: Media;

  constructor() {}

 }

library.scss

.edit-delete-btns {
    display: none;
    z-index: 102;
}

.category-name:hover ~ .edit-delete-btns {
    display: inline-block; //this works in the top level to show the buttons
}

/deep/ div > ul > li > .libraryCompClass > .library > .category-name:hover ~ .edit-delete-btns {
    display: inline-block; //my attempt at chaining classes to reach the deeper elements in the child component
}

.category-name { 
    z-index: 101;
}

.edit-delete-btns:hover {
    display: inline-block;
}

Any ideas would be helpful, thanks!

Austin
  • 115
  • 1
  • 10
  • I figured it out, I was missing a boolean attribute in my nested library component that was preventing the buttons from showing. – Austin Aug 28 '17 at 20:06

1 Answers1

0

Have you seen Angular 4.3 Now Available

Support for the emulated /deep/ CSS Selector (the Shadow-Piercing descendant combinator aka >>>) has been deprecated to match browser implementations and Chrome’s intent to remove. ::ng-deep has been added to provide a temporary workaround for developers currently using this feature.

Ironically I saw /deep/ in an Angular video today for the first time. So it was very fresh in my mind. I Googled it and linked the author of the video this and this asking if it still worked.
He made me aware of the release notes..

Seems even ::ng-deep is on the way out

JGFMK
  • 8,425
  • 4
  • 58
  • 92