Skip to content

Commit b78b87d

Browse files
committed
fix: allow scrolling on clickable elements on mobile
Closes #867
1 parent eb1ddfe commit b78b87d

File tree

6 files changed

+53
-13
lines changed

6 files changed

+53
-13
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ As there are so many events to show on each month, it doesn’t provide a lot of
118118

119119
### Does this calendar work with mobile?
120120

121-
This library is not optimised for mobile. Due to the complex nature of a calendar component, it is non trivial to build a calendar that has a great UX on both desktop and mobile. It is recommended to build your own calendar component for mobile that has a dedicated UX. You may be able to get some degree of mobile support by setting some custom CSS rules for smaller screens and [including hammerjs](http://hammerjs.github.io/) but your mileage may vary.
121+
This library is not optimised for mobile. Due to the complex nature of a calendar component, it is non trivial to build a calendar that has a great UX on both desktop and mobile. It is recommended to build your own calendar component for mobile that has a dedicated UX. You may be able to get some degree of mobile support by setting some custom CSS rules for smaller screens, [including hammerjs](http://hammerjs.github.io/) and using a [custom hammerjs config](https://github.com/mattlewis92/angular-calendar/blob/master/projects/demos/app/hammer-config.ts) to allow scrolling on clickable elements.
122122

123123
### How do I use a custom template?
124124

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@
131131
"@angular/core": ">=6.0.0 <9.0.0"
132132
},
133133
"dependencies": {
134-
"angular-draggable-droppable": "^4.0.2",
135-
"angular-resizable-element": "^3.2.2",
134+
"angular-draggable-droppable": "^4.2.0",
135+
"angular-resizable-element": "^3.2.4",
136136
"calendar-utils": "^0.2.2",
137137
"positioning": "^1.4.0"
138138
},

projects/angular-calendar/src/modules/common/click.directive.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const clickElements = new Set<HTMLElement>();
1616
selector: '[mwlClick]'
1717
})
1818
export class ClickDirective implements OnInit, OnDestroy {
19-
@Output('mwlClick') click: EventEmitter<MouseEvent> = new EventEmitter(); // tslint:disable-line
19+
@Output('mwlClick') click = new EventEmitter<MouseEvent>(); // tslint:disable-line
2020

2121
private removeListener: () => void;
2222

@@ -27,6 +27,11 @@ export class ClickDirective implements OnInit, OnDestroy {
2727
) {}
2828

2929
ngOnInit(): void {
30+
this.renderer.setAttribute(
31+
this.elm.nativeElement,
32+
'data-calendar-clickable',
33+
'true'
34+
);
3035
clickElements.add(this.elm.nativeElement);
3136
const eventName: string =
3237
typeof window !== 'undefined' && typeof window['Hammer'] !== 'undefined'

projects/demos/app/demo-app.module.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule } from '@angular/router';
3-
import { BrowserModule } from '@angular/platform-browser';
3+
import {
4+
BrowserModule,
5+
HAMMER_GESTURE_CONFIG
6+
} from '@angular/platform-browser';
47
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
58
import { NgbTabsetModule, NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
69
import { Angulartics2Module } from 'angulartics2';
7-
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
810
import { DemoAppComponent } from './demo-app.component';
911
import { DemoComponent as DefaultDemoComponent } from './demo-modules/kitchen-sink/component';
1012
import { DemoModule as DefaultDemoModule } from './demo-modules/kitchen-sink/module';
1113
import { environment } from '../environments/environment';
14+
import { CustomHammerConfig } from './hammer-config';
1215

1316
@NgModule({
1417
declarations: [DemoAppComponent],
@@ -297,6 +300,12 @@ import { environment } from '../environments/environment';
297300
developerMode: !environment.production
298301
})
299302
],
303+
providers: [
304+
{
305+
provide: HAMMER_GESTURE_CONFIG,
306+
useClass: CustomHammerConfig
307+
}
308+
],
300309
bootstrap: [DemoAppComponent]
301310
})
302311
export class DemoAppModule {}

projects/demos/app/hammer-config.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { HammerGestureConfig } from '@angular/platform-browser';
2+
3+
declare const Hammer: any;
4+
5+
export class CustomHammerConfig extends HammerGestureConfig {
6+
buildHammer(element: HTMLElement) {
7+
let options = {};
8+
9+
if (element.hasAttribute('data-calendar-clickable')) {
10+
options = { touchAction: 'pan-y' };
11+
}
12+
13+
const mc = new Hammer(element, options);
14+
15+
// keep default angular config
16+
mc.get('pinch').set({ enable: true });
17+
mc.get('rotate').set({ enable: true });
18+
19+
// retain support for angular overrides object
20+
Object.keys(this.overrides).forEach(eventName => {
21+
mc.get(eventName).set(this.overrides[eventName]);
22+
});
23+
24+
return mc;
25+
}
26+
}

0 commit comments

Comments
 (0)