feat(ui): completar presentacion de figuras UX-06D
This commit is contained in:
+23
-2
@@ -1,4 +1,5 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { Component, ElementRef, inject, OnDestroy, OnInit, signal, ViewChild } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
@@ -7,6 +8,26 @@ import { RouterOutlet } from '@angular/router';
|
||||
styleUrl: './app.scss',
|
||||
templateUrl: './app.html',
|
||||
})
|
||||
export class App {
|
||||
export class App implements OnInit, OnDestroy {
|
||||
protected readonly title = 'Plataforma de Indicadores';
|
||||
readonly showBackToTop = signal(false);
|
||||
@ViewChild('mainContent') private mainContent?: ElementRef<HTMLElement>;
|
||||
private readonly browserWindow = inject(DOCUMENT).defaultView;
|
||||
private readonly updateScroll = () => this.showBackToTop.set((this.browserWindow?.scrollY ?? 0) > 400);
|
||||
|
||||
ngOnInit() {
|
||||
this.updateScroll();
|
||||
this.browserWindow?.addEventListener('scroll', this.updateScroll, { passive: true });
|
||||
}
|
||||
|
||||
backToTop() {
|
||||
const reducedMotion = this.browserWindow?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
||||
// Keep keyboard focus near the destination when the floating button disappears.
|
||||
this.mainContent?.nativeElement.focus({ preventScroll: true });
|
||||
this.browserWindow?.scrollTo({ top: 0, behavior: reducedMotion ? 'instant' : 'smooth' });
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.browserWindow?.removeEventListener('scroll', this.updateScroll);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user