11import { CommonModule , isPlatformBrowser } from '@angular/common' ;
2- import { ChangeDetectionStrategy , Component , computed , ContentChild , ContentChildren , inject , InjectionToken , input , Input , NgModule , numberAttribute , QueryList , TemplateRef , ViewEncapsulation } from '@angular/core' ;
2+ import { ChangeDetectionStrategy , Component , computed , ContentChild , ContentChildren , inject , InjectionToken , input , Input , NgModule , numberAttribute , QueryList , signal , TemplateRef , ViewEncapsulation } from '@angular/core' ;
33import { MotionEvent , MotionOptions } from '@primeuix/motion' ;
44import { getWindowScrollTop } from '@primeuix/utils' ;
55import { PrimeTemplate , SharedModule } from 'primeng/api' ;
66import { BaseComponent , PARENT_INSTANCE } from 'primeng/basecomponent' ;
77import { Bind } from 'primeng/bind' ;
88import { Button , ButtonProps } from 'primeng/button' ;
99import { ChevronUpIcon } from 'primeng/icons' ;
10- import { MotionModule } from 'primeng/motion' ;
10+ import { MotionDirective } from 'primeng/motion' ;
1111import { ScrollTopPassThrough } from 'primeng/types/scrolltop' ;
1212import { ZIndexUtils } from 'primeng/utils' ;
1313import { ScrollTopStyle } from './style/scrolltopstyle' ;
@@ -21,10 +21,26 @@ const SCROLLTOP_INSTANCE = new InjectionToken<ScrollTop>('SCROLLTOP_INSTANCE');
2121@Component ( {
2222 selector : 'p-scrollTop, p-scrolltop, p-scroll-top' ,
2323 standalone : true ,
24- imports : [ CommonModule , ChevronUpIcon , Button , SharedModule , MotionModule ] ,
24+ imports : [ CommonModule , ChevronUpIcon , Button , SharedModule , MotionDirective ] ,
2525 template : `
26- <p-motion [visible]="visible" name="p-scrolltop" [options]="computedMotionOptions()" (onBeforeEnter)="onBeforeEnter($event)" (onBeforeLeave)="onBeforeLeave()">
27- <p-button [attr.aria-label]="buttonAriaLabel" (click)="onClick()" [pt]="ptm('pcButton')" [styleClass]="cn(cx('root'), styleClass)" [ngStyle]="style" type="button" [buttonProps]="buttonProps" [unstyled]="unstyled()">
26+ @if (render()) {
27+ <p-button
28+ [pMotion]="visible()"
29+ [pMotionAppear]="true"
30+ [pMotionName]="'p-scrolltop'"
31+ [pMotionOptions]="computedMotionOptions()"
32+ (pMotionOnBeforeEnter)="onBeforeEnter($event)"
33+ (pMotionOnBeforeLeave)="onBeforeLeave()"
34+ (pMotionOnAfterLeave)="onAfterLeave()"
35+ [attr.aria-label]="buttonAriaLabel"
36+ (click)="onClick()"
37+ [pt]="ptm('pcButton')"
38+ [styleClass]="cn(cx('root'), styleClass)"
39+ [ngStyle]="style"
40+ type="button"
41+ [buttonProps]="buttonProps"
42+ [unstyled]="unstyled()"
43+ >
2844 <ng-template #icon>
2945 <ng-container *ngIf="!iconTemplate && !_iconTemplate">
3046 <span *ngIf="_icon" [class]="cn(cx('icon'), _icon)"></span>
@@ -33,7 +49,7 @@ const SCROLLTOP_INSTANCE = new InjectionToken<ScrollTop>('SCROLLTOP_INSTANCE');
3349 <ng-template [ngIf]="!icon" *ngTemplateOutlet="iconTemplate || _iconTemplate; context: { styleClass: cx('icon') }"></ng-template>
3450 </ng-template>
3551 </p-button>
36- </p-motion>
52+ }
3753 ` ,
3854 changeDetection : ChangeDetectionStrategy . OnPush ,
3955 encapsulation : ViewEncapsulation . None ,
@@ -135,7 +151,9 @@ export class ScrollTop extends BaseComponent<ScrollTopPassThrough> {
135151
136152 parentScrollListener : VoidFunction | null | undefined ;
137153
138- visible : boolean = false ;
154+ visible = signal < boolean > ( false ) ;
155+
156+ render = signal < boolean > ( false ) ;
139157
140158 overlay : any ;
141159
@@ -175,10 +193,19 @@ export class ScrollTop extends BaseComponent<ScrollTopPassThrough> {
175193 this . overlay = null ;
176194 }
177195
196+ onAfterLeave ( ) {
197+ this . render . set ( false ) ;
198+ }
199+
178200 checkVisibility ( scrollY : number ) {
179- if ( scrollY > this . threshold ) this . visible = true ;
180- else this . visible = false ;
181- this . cd . markForCheck ( ) ;
201+ if ( scrollY > this . threshold ) {
202+ this . visible . set ( true ) ;
203+ if ( ! this . render ( ) ) {
204+ this . render . set ( true ) ;
205+ }
206+ } else {
207+ this . visible . set ( false ) ;
208+ }
182209 }
183210
184211 bindParentScrollListener ( ) {
0 commit comments