Focus the first field of a MessageForm when it is displayed#134
Merged
Conversation
`MessageForm.focus()` used to focus the first invalid field, and only fell back to the first field if no field was invalid. It is called both when the form is displayed (by `CommandDialog` and `CommandWizard`) and after a validation failure, which are two different expectations. All fields of a form that has just been displayed are empty, and those that have validation constraints report themselves invalid because of this. Such a field was focused instead of the form's first one. Focus the first field in `focus()`, and extract the search of the field that has caused a validation failure into `focusInvalidField()`, which the validation paths of `updateMessage()` now use. Since focus requests are dispatched asynchronously and a nested form receives them via its `focus()`, `focusInvalidField()` tells a nested form to focus its invalid field as well. Otherwise, focusing an invalid field edited by a nested form would focus that form's first field, overwriting the invalid one chosen by the validation cascade. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
armiol
approved these changes
Jul 16, 2026
dpikhulya
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #133.
What
When a dialog (or wizard page) containing a
MessageFormis opened, thefocus now lands on the form's first field. Previously it landed on an
arbitrary field in the middle of the form — the first one that reported
itself invalid, which on a pristine form merely means "empty with
validation constraints".
Details
MessageForm.focus()conflated two behaviors wanted by different callers:focusing the first field (when the form is displayed) and focusing the
first invalid field (after a failed validation). This change splits them:
focus()— theFocusableComponentoverride invoked byCommandDialogand
CommandWizardwhen the form is displayed — now focuses the form'sfirst field, keeping the existing oneof handling (if the first field is
a oneof, its selected option receives the focus).
focusInvalidField()method keeps the first-invalid-field searchand falls back to
focus()when no field is invalid. The two validationfailure paths in
updateMessage()now call it, which is what theirguarding parameter's name always implied.
Since focus requests are dispatched asynchronously and a nested form can
only be entered through its
focus()method, a new internalfocusInvalidFieldRequestedflag tells a nested form that the incomingfocus request targets its invalid field rather than its first one. This
preserves the previous behavior where a validation failure focuses the
invalid entry however deeply it is nested.
The
focusInvalidFieldparameter of the privateupdateMessagemethod isrenamed to
focusInvalidPart, aligning it with the publicupdateValidationDisplay(focusInvalidPart)API and freeing the name forthe new method.
Other changes
2.0.0-SNAPSHOT.89and regeneratedpom.xmlanddependencies.md.