Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Scrollbar fix scroll leaking to both directions #9217

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)));
}
}
Loading