Guard onFieldSubmitted on non-empty text to prevent cleared values reappearing

When a user clears a tag value and presses Done, RawAutocomplete's
onFieldSubmitted auto-selects the first option from the suggestions
list. Since optionsBuilder returns all suggestions for empty text,
this causes the cleared value to reappear. Guarding the call on
non-empty text prevents the auto-selection while preserving
autocomplete behavior when the user has typed a partial match.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Doug Borg
2026-02-10 18:56:28 -07:00
parent c7cfdc471c
commit af42e18f6e

View File

@@ -132,7 +132,14 @@ class _NSITagValueFieldState extends State<NSITagValueField> {
onChanged: (value) {
widget.onChanged(value);
},
onSubmitted: (_) => onFieldSubmitted(),
onSubmitted: (_) {
// Only auto-complete when there's text to match against.
// Otherwise, pressing Done on an empty field would auto-select
// the first suggestion, preventing users from clearing values.
if (controller.text.isNotEmpty) {
onFieldSubmitted();
}
},
);
},
optionsViewBuilder: (