Skip to content

fix(timepicker): allowing better scroll on touchpads #6292 - 19.2 #15639

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

Merged
merged 12 commits into from
Jul 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,13 @@ describe('IgxDateTimeEditor', () => {
inputElement.triggerEventHandler('focus', {});
fixture.detectChanges();
dateTimeEditorDirective.nativeElement.setSelectionRange(1, 1);
inputElement.triggerEventHandler('wheel', new WheelEvent('wheel', { deltaY: 1 }));
// typical wheel scrolls are 120px and the date-editor employs touchpad-friendly implementation
// that accumulates to 50 before incrementing/decrementing
// we'll test the behavior by doing two scrolls with the first one not expected to trigger a change
inputElement.triggerEventHandler('wheel', new WheelEvent('wheel', { deltaY: 20 }));
fixture.detectChanges();
expect(dateTimeEditorDirective.value.getDate()).toEqual(today.getDate());
inputElement.triggerEventHandler('wheel', new WheelEvent('wheel', { deltaY: 40 }));
fixture.detectChanges();
expect(dateTimeEditorDirective.value.getDate()).toEqual(today.getDate() - 1);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
@Output()
public validationFailed = new EventEmitter<IgxDateTimeEditorEventArgs>();


private readonly SCROLL_THRESHOLD = 50;
private _inputFormat: string;
private _scrollAccumulator = 0;
private _displayFormat: string;
private _oldValue: Date;
private _dateValue: Date;
Expand Down Expand Up @@ -314,10 +317,14 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
}
event.preventDefault();
event.stopPropagation();
if (event.deltaY > 0) {
this.decrement();
} else {
this.increment();
this._scrollAccumulator += event.deltaY;
if (Math.abs(this._scrollAccumulator) > this.SCROLL_THRESHOLD) {
if (this._scrollAccumulator > 0) {
this.decrement();
} else {
this.increment();
}
this._scrollAccumulator = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class IgxItemListDirective implements OnInit, OnDestroy {

public isActive: boolean;

private readonly SCROLL_THRESHOLD = 50;
private readonly PAN_THRESHOLD = 10;

/**
* accumulates wheel scrolls and triggers a change action above SCROLL_THRESHOLD
*/
private scrollAccumulator = 0;

constructor(
@Inject(IGX_TIME_PICKER_COMPONENT) public timePicker: IgxTimePickerBase,
private elementRef: ElementRef,
Expand Down Expand Up @@ -170,24 +178,35 @@ export class IgxItemListDirective implements OnInit, OnDestroy {
event.preventDefault();
event.stopPropagation();

const delta = event.deltaY;
if (delta !== 0) {
this.nextItem(delta);
this.scrollAccumulator += event.deltaY;
if (Math.abs(this.scrollAccumulator) > this.SCROLL_THRESHOLD) {
this.nextItem(this.scrollAccumulator);
this.scrollAccumulator = 0;
}
}

/**
* @hidden @internal
*/
public ngOnInit() {
const hammerOptions: HammerOptions = { recognizers: [[HammerGesturesManager.Hammer?.Pan, { direction: HammerGesturesManager.Hammer?.DIRECTION_VERTICAL, threshold: 10 }]] };
const hammerOptions: HammerOptions = {
recognizers: [
[
HammerGesturesManager.Hammer?.Pan,
{
direction: HammerGesturesManager.Hammer?.DIRECTION_VERTICAL,
threshold: this.PAN_THRESHOLD
}
]
]
};
this.touchManager.addEventListener(this.elementRef.nativeElement, 'pan', this.onPanMove, hammerOptions);
}

/**
* @hidden @internal
*/
public ngOnDestroy() {
public ngOnDestroy() {
this.touchManager.destroy();
}

Expand Down Expand Up @@ -355,7 +374,7 @@ export class IgxTimeItemDirective {
private getHourPart(date: Date): string {
const inputDateParts = DateTimeUtil.parseDateTimeFormat(this.timePicker.appliedFormat);
const hourPart = inputDateParts.find(element => element.type === 'hours');
const ampmPart = inputDateParts.find(element =>element.format.indexOf('a') !== -1 || element.format === 'tt');
const ampmPart = inputDateParts.find(element => element.format.indexOf('a') !== -1 || element.format === 'tt');
const hour = DateTimeUtil.getPartValue(date, hourPart, hourPart.format.length);
if (ampmPart) {
const ampm = DateTimeUtil.getPartValue(date, ampmPart, ampmPart.format.length);
Expand Down
Loading