Skip to content

Commit 4a0e581

Browse files
committed
fix(month-view): add 1px drag sensitivity
Fixes #1012
1 parent f7ad18d commit 4a0e581

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

projects/angular-calendar/src/modules/common/calendar-drag-helper.provider.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { isInside } from './util';
1+
import { isInside, isWithinThreshold } from './util';
22
import { ValidateDragParams } from 'angular-draggable-droppable';
33

4-
const DRAG_THRESHOLD = 1;
5-
64
export class CalendarDragHelper {
75
private readonly startPosition: ClientRect;
86

@@ -26,9 +24,6 @@ export class CalendarDragHelper {
2624
dragAlreadyMoved: boolean;
2725
transform: ValidateDragParams['transform'];
2826
}): boolean {
29-
const isWithinThreshold =
30-
Math.abs(x) > DRAG_THRESHOLD || Math.abs(y) > DRAG_THRESHOLD;
31-
3227
if (snapDraggedEvents) {
3328
const newRect: ClientRect = Object.assign({}, this.startPosition, {
3429
left: this.startPosition.left + transform.x,
@@ -38,11 +33,11 @@ export class CalendarDragHelper {
3833
});
3934

4035
return (
41-
(isWithinThreshold || dragAlreadyMoved) &&
36+
(isWithinThreshold({ x, y }) || dragAlreadyMoved) &&
4237
isInside(this.dragContainerElement.getBoundingClientRect(), newRect)
4338
);
4439
} else {
45-
return isWithinThreshold || dragAlreadyMoved;
40+
return isWithinThreshold({ x, y }) || dragAlreadyMoved;
4641
}
4742
}
4843
}

projects/angular-calendar/src/modules/common/util.ts

+5
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,8 @@ export function getWeekViewPeriod(
169169
return { viewStart, viewEnd };
170170
}
171171
}
172+
173+
export function isWithinThreshold({ x, y }: { x: number; y: number }) {
174+
const DRAG_THRESHOLD = 1;
175+
return Math.abs(x) > DRAG_THRESHOLD || Math.abs(y) > DRAG_THRESHOLD;
176+
}

projects/angular-calendar/src/modules/month/calendar-month-cell.component.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TemplateRef
77
} from '@angular/core';
88
import { MonthViewDay, CalendarEvent } from 'calendar-utils';
9-
import { trackByEventId } from '../common/util';
9+
import { isWithinThreshold, trackByEventId } from '../common/util';
1010
import { PlacementArray } from 'positioning';
1111

1212
@Component({
@@ -25,6 +25,7 @@ import { PlacementArray } from 'positioning';
2525
let-tooltipAppendToBody="tooltipAppendToBody"
2626
let-tooltipDelay="tooltipDelay"
2727
let-trackByEventId="trackByEventId"
28+
let-validateDrag="validateDrag"
2829
>
2930
<div class="cal-cell-top">
3031
<span class="cal-day-badge" *ngIf="day.badgeTotal > 0">{{
@@ -55,6 +56,7 @@ import { PlacementArray } from 'positioning';
5556
dragActiveClass="cal-drag-active"
5657
[dropData]="{ event: event, draggedFrom: day }"
5758
[dragAxis]="{ x: event.draggable, y: event.draggable }"
59+
[validateDrag]="validateDrag"
5860
(mwlClick)="eventClicked.emit({ event: event })"
5961
></div>
6062
</div>
@@ -72,7 +74,8 @@ import { PlacementArray } from 'positioning';
7274
tooltipTemplate: tooltipTemplate,
7375
tooltipAppendToBody: tooltipAppendToBody,
7476
tooltipDelay: tooltipDelay,
75-
trackByEventId: trackByEventId
77+
trackByEventId: trackByEventId,
78+
validateDrag: validateDrag
7679
}"
7780
>
7881
</ng-template>
@@ -117,4 +120,6 @@ export class CalendarMonthCellComponent {
117120
}>();
118121

119122
trackByEventId = trackByEventId;
123+
124+
validateDrag = isWithinThreshold;
120125
}

projects/angular-calendar/src/modules/month/calendar-open-day-events.component.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
AnimationTriggerMetadata
1414
} from '@angular/animations';
1515
import { CalendarEvent } from 'calendar-utils';
16-
import { trackByEventId } from '../common/util';
16+
import { isWithinThreshold, trackByEventId } from '../common/util';
1717

1818
export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
1919
transition('void => *', [
@@ -35,6 +35,7 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
3535
let-eventClicked="eventClicked"
3636
let-isOpen="isOpen"
3737
let-trackByEventId="trackByEventId"
38+
let-validateDrag="validateDrag"
3839
>
3940
<div class="cal-open-day-events" [@collapse] *ngIf="isOpen">
4041
<div
@@ -45,6 +46,7 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
4546
dragActiveClass="cal-drag-active"
4647
[dropData]="{ event: event }"
4748
[dragAxis]="{ x: event.draggable, y: event.draggable }"
49+
[validateDrag]="validateDrag"
4850
>
4951
<span
5052
class="cal-event"
@@ -74,7 +76,8 @@ export const collapseAnimation: AnimationTriggerMetadata = trigger('collapse', [
7476
events: events,
7577
eventClicked: eventClicked,
7678
isOpen: isOpen,
77-
trackByEventId: trackByEventId
79+
trackByEventId: trackByEventId,
80+
validateDrag: validateDrag
7881
}"
7982
>
8083
</ng-template>
@@ -98,4 +101,6 @@ export class CalendarOpenDayEventsComponent {
98101
}>();
99102

100103
trackByEventId = trackByEventId;
104+
105+
validateDrag = isWithinThreshold;
101106
}

0 commit comments

Comments
 (0)