Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormTokenField: Validate input before tokenizing on space #69262

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dhruvikpatel18
Copy link
Contributor

Closes #69252

What?

This PR fixes the FormTokenField component to properly validate input before creating tokens when pressing the space key.

Why?

Currently, when the tokenizeOnSpace prop is enabled, the FormTokenField component creates tokens immediately on space press without checking the experimentalValidateInput function. This can lead to invalid tokens being created, which is inconsistent with the validation behavior when using other methods of token creation (like pressing Enter or comma).

How?

Modified the space key handler in the onKeyDown function to:

  1. Check if there's valid input using inputHasValidValue()
  2. Call experimentalValidateInput with the current value
  3. Only create a token if both checks pass

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Feb 20, 2025
@youknowriad youknowriad requested a review from Mamaduka February 20, 2025 23:50
@dhruvikpatel18 dhruvikpatel18 marked this pull request as ready for review February 21, 2025 04:46
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dhruvikpatel18 <[email protected]>
Co-authored-by: alshakero <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormTokenField does not call __experimentalValidateInput before tokenizing on space
2 participants