ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

feat: add haptic feedback to Toggle in Safari on iOS 18+

Open jedlikowski opened this issue 1 year ago • 2 comments
trafficstars

Prerequisites

Describe the Feature Request

Safari since iOS 18 supports haptic feedback on checkbox elements via a non-standard switch attribute. We could use it to provide haptic feedback when switching Toggle in non-hybrid environments. This could be a workaround for lack of support for Vibration API in Safari.

Describe the Use Case

Adding haptic feedback to Toggle component in non-hybrid environments would improve native feel of web and PWA apps built with Ionic.

Describe Preferred Solution

To trigger haptic feedback programatically we need an <input type=checkbox switch> element with an associated <label> element. With this setup, when we programatically trigger click() on the label, safari will emit the haptic feedback.

Describe Alternatives

Keep current implementation and wait for Safari to implement Vibration API (if it ever does).

Related Code

Codepen provided in WebKit release notes, demonstrating haptic feedback in checkbox of type switch: https://codepen.io/jensimmons/pen/GReLKWg

Additional Information

No response

jedlikowski avatar Oct 16 '24 13:10 jedlikowski

This sounds really interesting! Would you mind to also include the option to configure this using IonicConfig with defaults to false?

You can find a similar PR for config extension here.

DwieDima avatar Oct 17 '24 13:10 DwieDima

Hi @DwieDima, thanks for the suggestion 🙇 Added configurability to my PR 😄

jedlikowski avatar Oct 18 '24 06:10 jedlikowski

Thank you for the feature request!

Are there any examples in the native iOS that provide haptic feedback? This will help determine if we would proceed with this request since we want to align with native.

thetaPC avatar Mar 18 '25 20:03 thetaPC

@thetaPC you can find these in the settings app for every toggle (e.g notifications)

DwieDima avatar Mar 18 '25 21:03 DwieDima

Thank you for providing a use case! I was able to verify that this is a possibility with native iOS and toggles. I'll be adding the feature request label so the team can look into this.

thetaPC avatar Mar 18 '25 23:03 thetaPC

Just came across this discussion - I've been working with the checkbox switch approach for haptic feedback in Safari on iOS as well. Created a small library that implements this technique: https://github.com/posaune0423/use-haptic. Might be useful as a reference for your implementation.

There's also a demo site if you want to try it out(code sandbox): https://kjwzkv.csb.app Might be useful as a reference for your implementation.

posaune0423 avatar Mar 31 '25 17:03 posaune0423

Thanks for the feature request! This has been resolved via PR https://github.com/ionic-team/ionic-framework/pull/29945 and will be available in an upcoming minor release of Ionic.

thetaPC avatar Apr 04 '25 20:04 thetaPC

Closing this as it was added in v8.6.0! Thank you!

thetaPC avatar Oct 06 '25 23:10 thetaPC

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Nov 05 '25 23:11 ionitron-bot[bot]