Skip to content

Commit c03dfea

Browse files
committed
refactor(toggle): use haptics on onClick
1 parent 35a05ae commit c03dfea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/src/components/toggle/toggle.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Component, Element, Event, Host, Prop, State, Watch, h } from '@stencil
33
import { renderHiddenInput, inheritAriaAttributes } from '@utils/helpers';
44
import type { Attributes } from '@utils/helpers';
55
import { hapticSelection } from '@utils/native/haptic';
6+
import { isPlatform } from '@utils/platform';
67
import { isRTL } from '@utils/rtl';
78
import { createColorClasses, hostContext } from '@utils/theme';
89
import { checkmarkOutline, removeOutline, ellipseOutline } from 'ionicons/icons';
@@ -247,6 +248,14 @@ export class Toggle implements ComponentInterface {
247248
}
248249

249250
private onClick = (ev: MouseEvent) => {
251+
/**
252+
* The haptics for the toggle is
253+
* an iOS-only feature when tapped.
254+
* As a result, it should be
255+
* disabled on Android.
256+
*/
257+
const enableHaptics = isPlatform('ios');
258+
250259
if (this.disabled) {
251260
return;
252261
}
@@ -255,6 +264,7 @@ export class Toggle implements ComponentInterface {
255264

256265
if (this.lastDrag + 300 < Date.now()) {
257266
this.toggleChecked();
267+
enableHaptics && hapticSelection();
258268
}
259269
};
260270

@@ -396,7 +406,6 @@ export class Toggle implements ComponentInterface {
396406
onBlur={() => this.onBlur()}
397407
ref={(focusEl) => (this.focusEl = focusEl)}
398408
required={required}
399-
{...({ switch: true } as any)}
400409
{...this.inheritedAttributes}
401410
/>
402411
<div

0 commit comments

Comments
 (0)