Skip to content

Commit

Permalink
fix(core): Scrollbar fix scroll leaking to both directions (#9217)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea authored Sep 26, 2024
1 parent 65981bc commit ff829fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion projects/core/components/scrollbar/scrollbar.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export class TuiScrollbarDirective {
.pipe(takeUntilDestroyed())
.subscribe(([top, left]) => {
this.el.style.scrollBehavior = 'auto';
this.el.scrollTo({top, left});

if (this.tuiScrollbar === 'horizontal') {
this.el.scrollLeft = left;
} else {
this.el.scrollTop = top;
}

this.el.style.scrollBehavior = '';
});

Expand Down
3 changes: 2 additions & 1 deletion projects/core/components/scrollbar/scrollbar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {inject, Injectable} from '@angular/core';
import {tuiTypedFromEvent, tuiZonefree} from '@taiga-ui/cdk/observables';
import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom';
import {TUI_SCROLL_REF} from '@taiga-ui/core/tokens';
import {map, merge, Observable, switchMap, takeUntil} from 'rxjs';
import {filter, map, merge, Observable, switchMap, takeUntil} from 'rxjs';

@Injectable()
export class TuiScrollbarService extends Observable<[number, number]> {
private readonly el = tuiInjectElement();
private readonly element = inject(TUI_SCROLL_REF).nativeElement;
private readonly scroll$ = merge(
tuiTypedFromEvent(this.el.parentElement!, 'mousedown').pipe(
filter(({target}) => target !== this.el),
map((event) => this.getScrolled(event, 0.5, 0.5)),
),
tuiTypedFromEvent(this.el, 'mousedown').pipe(
Expand Down
5 changes: 5 additions & 0 deletions projects/demo/src/modules/components/animations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
type="components"
>
<ng-template pageTab>
<p>
All CSS and Angular animations are controlled with
<code>TUI_ANIMATIONS_SPEED</code>
token with 1 being a default value
</p>
<label>
Speed of animations:
<input
Expand Down
5 changes: 3 additions & 2 deletions projects/demo/src/modules/components/animations/state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Injectable} from '@angular/core';
import {inject, Injectable} from '@angular/core';
import {TUI_ANIMATIONS_SPEED, tuiGetDuration} from '@taiga-ui/core';
import {BehaviorSubject} from 'rxjs';

@Injectable()
export class AnimationState extends BehaviorSubject<number> {
constructor() {
super(1000);
super(tuiGetDuration(inject(TUI_ANIMATIONS_SPEED)));
}
}

0 comments on commit ff829fc

Please sign in to comment.