Skip to content

Commit

Permalink
fix: description lines to collapse when expanding sibling (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored Jul 24, 2024
1 parent d59a659 commit cd10dfb
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/app/resume-page/collapsible-tree/collapsible-tree.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
QueryList,
ViewChildren,
} from '@angular/core'
import { MaterialSymbolDirective } from '@/common/material-symbol.directive'
import { NgComponentOutlet, NgTemplateOutlet } from '@angular/common'
import { NgComponentOutlet, NgForOf, NgTemplateOutlet } from '@angular/common'
import {
animate,
AUTO_STYLE,
Expand All @@ -28,7 +29,12 @@ let nextId = 0
@Component({
selector: 'app-collapsible-tree',
standalone: true,
imports: [MaterialSymbolDirective, NgTemplateOutlet, NgComponentOutlet],
imports: [
MaterialSymbolDirective,
NgTemplateOutlet,
NgComponentOutlet,
NgForOf,
],
templateUrl: './collapsible-tree.component.html',
styleUrl: './collapsible-tree.component.scss',
animations: [
Expand Down Expand Up @@ -63,6 +69,8 @@ export class CollapsibleTreeComponent {

private readonly _id = nextId++

constructor(private readonly cdRef: ChangeDetectorRef) {}

public get isCollapsible(): boolean {
if (!(this.node.children.length > 0)) {
return false
Expand All @@ -81,12 +89,17 @@ export class CollapsibleTreeComponent {
}

collapse() {
this.isExpanded = false
if (this.isExpanded) {
this.isExpanded = false
this.cdRef.markForCheck()
}
}

expand() {
this.isExpanded = true
this.parent?.collapseAllChildren({ except: this })
if (!this.isExpanded) {
this.isExpanded = true
this.parent?.collapseAllChildren({ except: this })
}
}

collapseAllChildren({ except }: { except?: CollapsibleTreeComponent } = {}) {
Expand Down

0 comments on commit cd10dfb

Please sign in to comment.