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
_hasInputValue is not updated on programmatic input value change #5410
The _hasInputValue property doesn't get updated when a field component clears or reverts its input value programmatically. The reason is that there is no corresponding input event in that case which can update _hasInputValue.
This becomes a significant issue when it comes to Flow component validation:
Example 1:
Type 1/1/ into a DatePicker – triggers _hasInputValue to become true
Press Esc to close the dropdown.
Result: the DatePicker is red despite no visible value.
Screen.Recording.2023-01-26.at.19.41.06.mov
Example 2:
Type 12:00 into a TimePicker with the clear button visible – triggers _hasInputValue to become true
Press Enter to commit the value.
Click on the clear button.
Result: the TimePicker is red despite no visible value.
Screen.Recording.2023-01-26.at.19.42.00.mov
Expected outcome
_hasInputValue should be updated whenever a field component of the user changes the input value programmatically.
Affected components
Basically, any component that supports the _hasInputValue property is potentially prone to this issue.
changed the title [-]The _hasInputValue property is not updated on programmatic input value clear[/-][+]The _hasInputValue property is not updated on programmatic input value change[/+]on Jan 26, 2023
Possible solution: Introduce an inputElementValue getter and setter in InputMixin (we have such getters and setters in some components already) and use those wherever there is a need for updating value instead of direct inputElement.value = '...' assignments.
changed the title [-]The _hasInputValue property is not updated on programmatic input value change[/-][+]`_hasInputValue` is not updated on programmatic input value change[/+]on Jan 30, 2023
There is one complication that I didn't realize immediately. To avoid Flow validation running with an outdated hasInputValue, the value-changed event – which triggers validation – should always come after has-input-value-changed. This is one of the things to take into account in this ticket.
Introduce an inputElementValue getter and setter in InputMixin (we have such getters and setters in some components already) and use those wherever there is a need for updating value instead of direct inputElement.value = '...' assignments.
In DatePicker's dropdown, you can select and deselect a date with Space which immediatelly affects the DatePicker value. If we simply sync _hasInputValue with the input value, after deselecting the date, DatePicker will have no value but _hasInputValue will be true because the date is still focused and, for this reason, displayed in the input element. Considering that, the right approach will be to reset _hasInputValue on programmatic input value changes.
This is how it will work in the DatePicker case:
The user enters 1/1/ (hasInputValue becomes true).
That causes the dropdown to open.
The user moves focus to another date in the dropdown.
That causes the input element value to change to the focused date (hasInputValue becomes false as it's not user input anymore).
With this approach, it may feel like the property should be rather called _hasUserInput. That's a valid point. Maybe we'll rename it at some point.
Activity
[-]The _hasInputValue property is not updated on programmatic input value clear[/-][+]The _hasInputValue property is not updated on programmatic input value change[/+]vursen commentedon Jan 27, 2023
Possible solution: Introduce an
inputElementValuegetter and setter inInputMixin(we have such getters and setters in some components already) and use those wherever there is a need for updatingvalueinstead of directinputElement.value = '...'assignments.[-]The _hasInputValue property is not updated on programmatic input value change[/-][+]`_hasInputValue` is not updated on programmatic input value change[/+]vursen commentedon Feb 22, 2023
There is one complication that I didn't realize immediately. To avoid Flow validation running with an outdated hasInputValue, the
value-changedevent – which triggers validation – should always come afterhas-input-value-changed. This is one of the things to take into account in this ticket.vursen commentedon Feb 24, 2023
In DatePicker's dropdown, you can select and deselect a date with Space which immediatelly affects the DatePicker value. If we simply sync
_hasInputValuewith the input value, after deselecting the date, DatePicker will have no value but_hasInputValuewill be true because the date is still focused and, for this reason, displayed in the input element. Considering that, the right approach will be to reset_hasInputValueon programmatic input value changes.This is how it will work in the DatePicker case:
1/1/(hasInputValue becomes true).With this approach, it may feel like the property should be rather called
_hasUserInput. That's a valid point. Maybe we'll rename it at some point.