ionChange will only emit from user committed changes #25532
Replies: 6 comments 1 reply
-
|
Thanks so much @sean-perkins for this awesome RFC! |
Beta Was this translation helpful? Give feedback.
-
|
You are awesome and an inspiration of mine sir |
Beta Was this translation helpful? Give feedback.
-
|
This sounds awesome thanks 😊 |
Beta Was this translation helpful? Give feedback.
-
|
This is a great suggestion. It is very weird that a basic use case like loading data for |
Beta Was this translation helpful? Give feedback.
-
|
what if user autofill their FORMS from password managers or anything like that? there should be an option to enable / disable for ionChange to trigger! |
Beta Was this translation helpful? Give feedback.
-
|
Hello everyone, thank you so much for expressing your feedback surrounding this RFC. We will be moving forward with this change to form controls in an upcoming major release of Ionic Framework. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Depending on the kind of element being changed and the way the user interacts with the element, the
ionChangeevent should fire at a different moment:ion-checkboxorion-radioelement is checked or unchecked (by clicking or using the keyboard);ion-selectdropdown with a mouse click, by selecting a date from theion-datetime, etc.);ion-textareaorion-input).The
ionChangeevent should not fire as a result of external value changes (e.g.: manually assigning a value).Motivation
Ionic Framework has had this API design for
ionChangefor quite some time. As a result, there have been a number of issues over the years and frustrations from developers; such as:ionChangeis emitted multiple times from a single (external) change eventionChangewas a result of the user interacting with the control or their app setting the value on the control.ionChangeis emitted at un-expected times, such as resetting the state of a form.This pattern is also inconsistent with HTML form elements, such as
input,textareaandselect.Related Issues:
ionChangeevent: determine whether it by user interaction #19651Proposed Design
There will be no change to the public API for
ionChange, while the behavior for whenionChangeis fired will change.The
ionChangeevent for each component will align to their equivalent HTML element, if available. Custom components without an equivalent, will fireionChangewhen the user commits the change explicitly. This will align the behavior ofionChangewith thechangeevent: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_eventInternally, the Ionic team will move away from this pattern:
This approach of listening for any internal/external change to
value, is the root cause of this architectural issue.The following components will be affected:
ion-accordion-groupion-checkbox(with thecheckedproperty)ion-datetimeion-inpution-radio-groupion-rangeion-searchbarion-segmention-selection-textareaion-toggleUsage
With the following example:
ionChangeis fired when the user types within theion-inputand the control is blurred.ionChangewill not fire whenmyValueis set to “Hello world”Benefits
changeevent pattern that developers expect from existing form elements (e.g.input,textarea).ionChangewill only be emitted as a result of committed value changes to the control. This provides developers a consistent API to respond to user interaction vs. setting the state of a form control.changeandinput, allowing Ionic to explore features such as input masking.Drawbacks
Since this pattern has existed in Ionic Framework for awhile, it is expected that developers have either written applications that have dependency on this pattern or have written custom code within their
ionChangeevent handlers, that uses comparisons to try and determine if the change is a result of user interaction. As a result, developers would need to audit their implementations after this change, to make sure that their applications continue to behave consistently or refactor them accordingly.Alternatives
Comparing Previous Value
Developers have been able to work around this pattern by comparing the previous value against the new value before handling the interaction.
The downsides of this implementation pattern is that it requires a lot of boilerplate in each
ionChangeevent handler. It also is difficult to discern between if the change event is from the initial value being set on the control or from the user changing the value for the first time.Skip First Emission
Developers may also have been able to work around this issue by ignoring the first emission of
ionChange, as it is likely a result of the value being set.This approach has many downsides. If the user was to interact with the control before the API response has been resolved, the interaction would be skipped. It also assumes that only a single interaction will manually set
this.myValue.Using
ionInputeventDevelopers can use the
ionInputon the components that support the event API, to only subscribe to changes when the user types.While this API suffices for
ion-input, it is not available for all Ionic form controls, such asion-datetime,ion-rangeandion-select.Breaking Changes
Listening for changes while focused (input, textarea)
Developers using the
ionChangeevent to listen for immediate value changes as the user types forion-inputorion-textarea, should migrate their implementations to use theionInputevent.Before
After
Developers can continue to use
ionChangeto listen for when the value is committed to the input. This happens when the control loses focus.debouncepropertyThe
debounceproperty onion-input,ion-textareaandion-searchbarcontrols the time in milliseconds to wait to triggerionChangeafter each keystroke. This behavior is invalid now thationChangeemits on blur.This behavior will be migrated to apply to the
ionInputevent instead. Developers usingdebounceonion-input,ion-textareaorion-searchbarwill delay the emission of theionInputevent after each keystroke.Beta Was this translation helpful? Give feedback.
All reactions