Skip to content

Commit 534b9c2

Browse files
crisbetojelbourn
authored andcommitted
feat(slide-toggle): remove Hammer.js dependency (#17102)
Removes the slide toggle's dependency on Hammer.js by getting rid of the dragging gestures.
1 parent 2001965 commit 534b9c2

File tree

8 files changed

+34
-409
lines changed

8 files changed

+34
-409
lines changed

src/material/slide-toggle/slide-toggle-config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import {InjectionToken} from '@angular/core';
1212
export interface MatSlideToggleDefaultOptions {
1313
/** Whether toggle action triggers value changes in slide toggle. */
1414
disableToggleValue?: boolean;
15-
/** Whether drag action triggers value changes in slide toggle. */
15+
/**
16+
* Whether drag action triggers value changes in slide toggle.
17+
* @deprecated No longer being used.
18+
* @breaking-change 10.0.0
19+
*/
1620
disableDragValue?: boolean;
1721
}
1822

1923
/** Injection token to be used to override the default options for `mat-slide-toggle`. */
2024
export const MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS =
2125
new InjectionToken<MatSlideToggleDefaultOptions>('mat-slide-toggle-default-options', {
2226
providedIn: 'root',
23-
factory: () => ({disableToggleValue: false, disableDragValue: false})
27+
factory: () => ({disableToggleValue: false})
2428
});

src/material/slide-toggle/slide-toggle-module.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import {ObserversModule} from '@angular/cdk/observers';
1010
import {NgModule} from '@angular/core';
11-
import {GestureConfig, MatCommonModule, MatRippleModule} from '@angular/material/core';
12-
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
11+
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1312
import {MatSlideToggle} from './slide-toggle';
1413
import {MatSlideToggleRequiredValidator} from './slide-toggle-required-validator';
1514

@@ -35,8 +34,5 @@ export class _MatSlideToggleRequiredValidatorModule {
3534
MatCommonModule
3635
],
3736
declarations: [MatSlideToggle],
38-
providers: [
39-
{provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig}
40-
],
4137
})
4238
export class MatSlideToggleModule {}

src/material/slide-toggle/slide-toggle.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616
(change)="_onChangeEvent($event)"
1717
(click)="_onInputClick($event)">
1818

19-
<div class="mat-slide-toggle-thumb-container"
20-
#thumbContainer
21-
(slidestart)="_onDragStart()"
22-
(slide)="_onDrag($event)"
23-
(slideend)="_onDragEnd()">
24-
19+
<div class="mat-slide-toggle-thumb-container" #thumbContainer>
2520
<div class="mat-slide-toggle-thumb"></div>
26-
2721
<div class="mat-slide-toggle-ripple" mat-ripple
2822
[matRippleTrigger]="label"
2923
[matRippleDisabled]="disableRipple || disabled"
@@ -33,10 +27,8 @@
3327

3428
<div class="mat-ripple-element mat-slide-toggle-persistent-ripple"></div>
3529
</div>
36-
3730
</div>
3831

39-
4032
</div>
4133

4234
<span class="mat-slide-toggle-content" #labelContent (cdkObserveContent)="_onLabelTextChange()">

src/material/slide-toggle/slide-toggle.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
`<mat-slide-toggle>` is an on/off control that can be toggled via clicking or dragging.
1+
`<mat-slide-toggle>` is an on/off control that can be toggled via clicking.
22

33
<!-- example(slide-toggle-overview) -->
44

5-
The slide-toggle behaves similarly to a checkbox, though it does not support an `indeterminate`
5+
The slide-toggle behaves similarly to a checkbox, though it does not support an `indeterminate`
66
state like `<mat-checkbox>`.
77

8-
_Note: the sliding behavior for this component requires that HammerJS is loaded on the page._
9-
108
### Slide-toggle label
11-
The slide-toggle label is provided as the content to the `<mat-slide-toggle>` element.
9+
The slide-toggle label is provided as the content to the `<mat-slide-toggle>` element.
1210

13-
If you don't want the label to appear next to the slide-toggle, you can use
14-
[`aria-label`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-label) or
15-
[`aria-labelledby`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby) to
11+
If you don't want the label to appear next to the slide-toggle, you can use
12+
[`aria-label`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-label) or
13+
[`aria-labelledby`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby) to
1614
specify an appropriate label.
1715

1816
### Use with `@angular/forms`
19-
`<mat-slide-toggle>` is compatible with `@angular/forms` and supports both `FormsModule`
17+
`<mat-slide-toggle>` is compatible with `@angular/forms` and supports both `FormsModule`
2018
and `ReactiveFormsModule`.
2119

2220
### Theming
23-
The color of a `<mat-slide-toggle>` can be changed by using the `color` property. By default,
24-
slide-toggles use the theme's accent color. This can be changed to `'primary'` or `'warn'`.
21+
The color of a `<mat-slide-toggle>` can be changed by using the `color` property. By default,
22+
slide-toggles use the theme's accent color. This can be changed to `'primary'` or `'warn'`.
2523

2624
### Accessibility
2725
The `<mat-slide-toggle>` uses an internal `<input type="checkbox">` to provide an accessible

src/material/slide-toggle/slide-toggle.scss

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import '../core/style/variables';
22
@import '../core/ripple/ripple';
3-
@import '../core/style/vendor-prefixes';
43
@import '../core/style/list-common';
54
@import '../../cdk/a11y/a11y';
65

@@ -23,10 +22,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
2322
white-space: nowrap;
2423
outline: none;
2524

26-
// Disable user selection to ensure that dragging is smooth without grabbing
27-
// some elements accidentally.
28-
@include user-select(none);
29-
3025
-webkit-tap-highlight-color: transparent;
3126

3227
&.mat-checked {
@@ -57,7 +52,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
5752
flex-direction: row;
5853
align-items: center;
5954
height: inherit;
60-
6155
cursor: pointer;
6256
}
6357

@@ -92,7 +86,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
9286
margin-right: 0;
9387
}
9488

95-
// The thumb container is responsible for the dragging functionality.
9689
// The container includes the visual thumb and the ripple container element.
9790
.mat-slide-toggle-thumb-container {
9891
$thumb-bar-vertical-padding: ($mat-slide-toggle-thumb-size - $mat-slide-toggle-bar-height) / 2;
@@ -109,18 +102,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
109102
transition: $swift-linear;
110103
transition-property: transform;
111104

112-
@include cursor-grab;
113-
114-
// Once the thumb container is being dragged around, we remove the transition duration to
115-
// make the drag feeling fast and not delayed.
116-
&.mat-dragging {
117-
transition-duration: 0ms;
118-
}
119-
120-
&:active {
121-
@include cursor-grabbing;
122-
}
123-
124105
._mat-animation-noopable & {
125106
transition: none;
126107
}

0 commit comments

Comments
 (0)