FormTokenField: Automatically add token on blur if there is valid content #16849
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.
Description
This PR adds functionality that adds the current input value as a new token on blur.
FormTokenField
was originally build with a feature that retains the input content that user wrote in the input (but doesn't add it as tag). See:This works great in theory but it turns out that it's super easy to move focus from the token input into the block editor and that will switch the context of the sidebar - making the tag input disappear (and forget the content next time it is opened). This is displayed in #16788
What would be the best solution? I like an explicit confirmation of tags (enter, comma) but losing the content is very easy and maybe something we should try to prevent.
I remember working on this component previously and we've had long discussion about the label "Separate with commas or the Enter key." which leaves one situation open to interpretation: "if I'm only adding a single token, I don't need any separator". Adding the token on blur would solve that problem too.
Fixes #16788
How has this been tested?
Screenshots
Types of changes
Checklist: