Skip to content

Commit

Permalink
feat(chipped-content): scroll to show displayed content (#110)
Browse files Browse the repository at this point in the history
* feat(chipped-content): scroll to show displayed content

* refactor(chipped-content): simplify content change method
  • Loading branch information
davidlj95 authored Oct 15, 2023
1 parent 0015c54 commit 20843f4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/app/about/chipped-content/chipped-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,24 @@ export class ChippedContentComponent implements OnInit {
}

async setSelectedContent(id: string) {
const content = this.contents.find((content) => content.id === id)!
this.contentHost.clear()

// Tapping same chip hides content
if (this.selectedContentId === id) {
const content = this.contents.find((content) => content.id === id)!
this.contentHost.clear()
this.selectedContentId = undefined
await content.waitForAnimationEnd(this.selectedContentComponent)
this.contentDisplayedChange.emit(false)
return
}

this.selectedContentId = id
this.contentHost.clear()
const content = this.contents.find((content) => content.id === id)!
this.addContentToHost(content)
const componentRef = this.addContentToHost(content)
this.contentDisplayedChange.emit(true)
await content.waitForAnimationEnd(componentRef.instance)
;(componentRef.location.nativeElement as HTMLElement).scrollIntoView({
block: 'nearest',
})
}

private hideContentElement(elementRef: ElementRef) {
Expand Down

0 comments on commit 20843f4

Please sign in to comment.