From 796e00720e0da90eda1d246a6d5b11f954e5993c Mon Sep 17 00:00:00 2001 From: Jakub Jedlikowski Date: Fri, 4 Apr 2025 22:53:01 +0200 Subject: [PATCH] feat(toggle): add iOS 18 haptic feedback (#29945) Co-authored-by: Maria Hutt Co-authored-by: Shane --- core/src/components/toggle/toggle.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/components/toggle/toggle.tsx b/core/src/components/toggle/toggle.tsx index 8ccdb60d3d..50c210d7c6 100644 --- a/core/src/components/toggle/toggle.tsx +++ b/core/src/components/toggle/toggle.tsx @@ -3,6 +3,7 @@ import { Component, Element, Event, Host, Prop, State, Watch, h } from '@stencil import { renderHiddenInput, inheritAriaAttributes } from '@utils/helpers'; import type { Attributes } from '@utils/helpers'; import { hapticSelection } from '@utils/native/haptic'; +import { isPlatform } from '@utils/platform'; import { isRTL } from '@utils/rtl'; import { createColorClasses, hostContext } from '@utils/theme'; import { checkmarkOutline, removeOutline, ellipseOutline } from 'ionicons/icons'; @@ -247,6 +248,13 @@ export class Toggle implements ComponentInterface { } private onClick = (ev: MouseEvent) => { + /** + * The haptics for the toggle on tap is + * an iOS-only feature. As such, it should + * only trigger on iOS. + */ + const enableHaptics = isPlatform('ios'); + if (this.disabled) { return; } @@ -255,6 +263,7 @@ export class Toggle implements ComponentInterface { if (this.lastDrag + 300 < Date.now()) { this.toggleChecked(); + enableHaptics && hapticSelection(); } };