Skip to content

Commit

Permalink
chore: remove warnings about scroll into view (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored Dec 23, 2024
1 parent b619faa commit 152eb00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app/common/scroll-into-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const scrollIntoView = (
element: Element,
...args: Parameters<Element['scrollIntoView']>
) => {
// 👇 For the server
if (element.scrollIntoView) {
element.scrollIntoView(...args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div
class="content"
[@contentDisplayed]="isActive()"
(@contentDisplayed.done)="contentElement.scrollIntoView({ block: 'nearest' })"
(@contentDisplayed.done)="onAnimationDone(contentElement)"
#contentElement
>
<ng-container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
transition,
trigger,
} from '@angular/animations'
import { scrollIntoView } from '@/common/scroll-into-view'

@Component({
selector: 'app-chipped-content',
Expand Down Expand Up @@ -54,4 +55,8 @@ export class ChippedContentComponent {
this.isActive.set(true)
this.activeContent.set(content)
}

onAnimationDone(contentElement: Element) {
scrollIntoView(contentElement, { block: 'nearest' })
}
}

0 comments on commit 152eb00

Please sign in to comment.