mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 10:01:59 +08:00
feat(toggle): add iOS 18 haptic feedback (#29945)
Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com> Co-authored-by: Shane <shane@shanessite.net>
This commit is contained in:

committed by
GitHub

parent
91477cfe23
commit
796e00720e
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user