You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: ionChange event: determine whether it by user interaction #19651
Additional Context
My use case: I have a dark mode toggle and on ionChange I save the user's preference. Until the user manually sets the toggle I use the OS setting (which I get using window.matchMedia('(prefers-color-scheme: dark)')). When the OS setting changes the toggle should change as well. But this saves the new value and no longer checks the OS preference.
In Ionic 3, I achieved this by using different handlers for the ionFocus and ionBlur events which would only respond to user interactions (i.e. not using ionChange). Now, these events only fire on tabbing, no longer on click. I will post here when I find a workaround.
ionFocus was ok in beta version of ionic 4. ionFocus is triggered only by user.
Now in ionic 5, it is only triggered if user change the position by a movement like "drag and drop" on the toggle.
In my case, I have to execute the function only if user touch the toggle:
My workaround is to use (click) instead of (ionFocus):
changed the title [-]bug: `ion-toggle` `ionChange` event: determine whether it by user interaction[/-][+]feat: `ionChange` event: determine whether it by user interaction[/+]on Feb 24, 2022
Hello everyone, this issue has been resolved and will be available in the next major release of Ionic (v7).
Any ionChange event emission will be the result of user interaction. We additionally are emitting the corresponding event that triggered the change. For example, if a click event triggered the ionChange, the event detail for that original event will be included in the ionChange custom event.
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.
Activity
liamdebeasi commentedon Oct 14, 2019
Looks like there is an open PR for this: #19509
alex-steinberg commentedon Apr 9, 2020
In Ionic 3, I achieved this by using different handlers for the
ionFocusandionBlurevents which would only respond to user interactions (i.e. not usingionChange). Now, these events only fire on tabbing, no longer on click. I will post here when I find a workaround.alex-steinberg commentedon Apr 9, 2020
Workaround here.
jeugregg commentedon Nov 26, 2020
ionFocus was ok in beta version of ionic 4. ionFocus is triggered only by user.
Now in ionic 5, it is only triggered if user change the position by a movement like "drag and drop" on the toggle.
In my case, I have to execute the function only if user touch the toggle:
My workaround is to use (click) instead of (ionFocus):
<ion-toggle color="secondary" slot="end" [(ngModel)]="myElement.enabled" (click)="enableElemFocusEvent($event, myElement)" disabled="{{myElement.inProgress}}"></ion-toggle>So, if the property
myElement.enabledis changed by another event, it didn't triggerenableElemFocusEvent.I think it is not normal, why change between version ? or I have an old version of something. I still use cordova.
I am with this configuration :
ionic info:[-]bug: `ion-toggle` `ionChange` event: determine whether it by user interaction[/-][+]feat: `ionChange` event: determine whether it by user interaction[/+]sean-perkins commentedon Jul 6, 2022
Hello everyone, we have an open RFC that proposes a change to
ionChangethat would help alleviate this issue.Please take a moment to review and let us know your thoughts: #25532
sean-perkins commentedon Nov 9, 2022
Hello everyone, this issue has been resolved and will be available in the next major release of Ionic (v7).
Any
ionChangeevent emission will be the result of user interaction. We additionally are emitting the corresponding event that triggered the change. For example, if a click event triggered theionChange, the event detail for that original event will be included in theionChangecustom event.ionitron-bot commentedon Dec 9, 2022
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.