1
1
# V9 HammerJS migration
2
2
3
- In Angular Material version 9, the dependency on HammerJS has been dropped . Components which
3
+ Angular Material, as of version 9, no longer requires HammerJS for any component . Components which
4
4
previously depended on HammerJS, no longer provide a [ ` HAMMER_GESTURE_CONFIG ` ] [ 1 ] that will
5
5
enable use of HammerJS events in templates.
6
6
@@ -10,33 +10,37 @@ deprecated and will be removed in version 10.
10
10
### Why is a migration needed?
11
11
12
12
Since HammerJS previously was a requirement for a few Angular Material components, projects might
13
- have installed ` HammerJS ` for these. Since HammerJS is no longer needed when updating to v9, the
14
- dependency on HammerJS can be unnecessary and should be removed.
13
+ have installed ` HammerJS ` exclusively for Angular Material. Since HammerJS is no longer needed when
14
+ updating to v9, the dependency on HammerJS can be removed if it's not used directly in the
15
+ application.
15
16
16
17
In some cases, projects use HammerJS events in templates while relying on Angular Material
17
18
modules to set up the HammerJS event plugin. Since this is no longer the case in version 9,
18
19
such projects need to manually configure the HammerJS event plugin in order to continue using
19
20
these HammerJS events.
20
21
21
- ### How does the migration work ?
22
+ ### What does the migration do ?
22
23
23
- The migration automatically removes HammerJS from the project if HammerJS is not used in the
24
- project anywhere. If HammerJS events provided by the deprecated ` GestureConfig ` are used in
25
- templates, the migration will set up a new config that supports the used events, and the
26
- ` HammerModule ` which enables event bindings to HammerJS in templates.
24
+ The migration automatically removes HammerJS from the project if HammerJS is not used.
27
25
28
- In case a custom [ ` HAMMER_GESTURE_CONFIG ` ] [ 1 ] is provided and there are references to the
26
+ Additionally, Angular Material's ` GestureConfig ` (now deprecated) defined custom HammerJS gestures.
27
+ If the application directly uses any of these gestures, the migration will introduce a new
28
+ application-specific configuration for these custom gestures, removing the dependency on Angular
29
+ Material's ` GestureConfig ` .
30
+
31
+ Finally, if the application uses HammerJS directly, the migration will add an import for Angular's
32
+ new ` HammerModule ` , which enabled HammerJS event bindings. These bindings were previously enabled
33
+ by default in Angular versions 8 and below.
34
+
35
+ If your application provides a custom [ ` HAMMER_GESTURE_CONFIG ` ] [ 1 ] and also references the
29
36
deprecated Angular Material ` GestureConfig ` , the migration will print a warning about
30
37
ambiguous usage. The migration cannot migrate the project automatically and manual changes
31
38
are required. Read more [ in the dedicated section] ( #The-migration-reported-ambiguous-usage-What-should-I-do ) .
32
39
33
- ### How can I remove HammerJS from the project?
34
-
35
- As explained in the section above, if you do not use HammerJS in your project, the migration
36
- removes HammerJS from your project. The migration performs the following steps:
40
+ ### How does the schematic remove HammerJS?
37
41
38
- _ Disclaimer: _ HammerJS can be set up in lots of different ways. The migration only handles
39
- the most common cases which were also recommended by Angular Material in the past.
42
+ HammerJS can be set up in many ways. The migration handles the most common cases, covering
43
+ approaches recommended by Angular Material in the past. The migration performs the following steps:
40
44
41
45
* 1\. * Remove ` hammerjs ` from the project ` package.json ` .
42
46
``` json
@@ -55,14 +59,14 @@ the most common cases which were also recommended by Angular Material in the pas
55
59
import ' hammerjs' ;
56
60
```
57
61
58
- The migration does not automatically remove HammerJS from tests. Please manually clean up
59
- the test setup, and resolve any test issues. Read more in a [ dedicated section for test migration] ( #How-to-migrate-my-tests )
62
+ The migration cannot automatically remove HammerJS from tests. Please manually clean up
63
+ the test setup and resolve any test issues. Read more in a
64
+ [ dedicated section for test migration] ( #How-to-migrate-my-tests )
60
65
61
66
### How do I migrate references to the deprecated ` GestureConfig ` ?
62
67
63
- The ` GestureConfig ` can be consumed in a lot of possible ways. This section only covers the
64
- most common cases which are also handled by the migration. The most common case is that the
65
- deprecated ` GestureConfig ` is manually provided in an ` NgModule ` of the project.
68
+ The ` GestureConfig ` can be consumed in multiple ways. The migration covers the most common cases.
69
+ The most common case is that an ` NgModule ` in your application directly provides ` GestureConfig ` :
66
70
67
71
``` typescript
68
72
import {GestureConfig } from ' @angular/material/core' ;
@@ -76,7 +80,7 @@ import {GestureConfig} from '@angular/material/core';
76
80
export class AppModule {}
77
81
```
78
82
79
- If such pattern can be found in the project, it usually means that a component relies on the
83
+ If this pattern is found in the project, it usually means that a component relies on the
80
84
deprecated ` GestureConfig ` in order to use HammerJS events in the template. If this is the case,
81
85
the migration automatically creates a new gesture config which supports the used HammerJS
82
86
events. All references to the deprecated gesture config will be rewritten to the newly created one.
@@ -91,7 +95,7 @@ automatically, but the migration will report such patterns and ask for manual cl
91
95
<a name =" test-migration " ></a >
92
96
### How to migrate my tests?
93
97
94
- Components of your project might use Angular Material components which previously depended
98
+ Components in your project might use Angular Material components which previously depended
95
99
on HammerJS. There might be unit tests for these components which also test gesture functionality
96
100
of the Angular Material components. For such unit tests, find all failing gesture tests. These
97
101
might need to be reworked to dispatch proper events to simulate gestures, or need to be deleted.
0 commit comments