fix(NumberField/NumberFieldRoot): emit update:modelValue events after child input event (#1720) #1721
+50
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the NumberFieldRoot component would only emit
update:modelValue
events when the child input element emitted achange
event, which only occurs after the user has finished making changes and leaves the field. This is not consistent with the behaviour you would see on a native input where the value changes after everyinput
event, after each keypress and intermediary value entered.This PR makes changes to how the text value is displayed and how the model value is emitted, allowing the model value to emit more frequently as the user types (after an
input
event occurs), while not affecting the existing behaviour of when any formatting, clamping, or snapping is applied to the displayed value.Additionally, the emitted model value pre-calculates any clamping or snapping to ensure that it reflects what the displayed text value will change to if the user were to hit 'enter' or leave the field.
This is done by removing the existing
computed
property which tied the displayed text value firmly to the current model value, and instead uses a watcher which can react to changes in any prop values that affect the text value, but selectively ignore a change when it is known to be caused by a user input which may not yet be fully complete.Addresses #1720