Skip to content

Fix: Preserve natural tab order in DataForm card layout validation#76839

Closed
Shekhar0109 wants to merge 2 commits intoWordPress:trunkfrom
Shekhar0109:fix/dataform-blur-focus-76832
Closed

Fix: Preserve natural tab order in DataForm card layout validation#76839
Shekhar0109 wants to merge 2 commits intoWordPress:trunkfrom
Shekhar0109:fix/dataform-blur-focus-76832

Conversation

@Shekhar0109
Copy link
Copy Markdown
Contributor

What?

Fixes an issue where validation triggered on blur moves focus to the first invalid field, breaking the natural tab sequence in the DataForm card layout.

Closes #76832

Why?

reportValidity() automatically focuses the invalid input element. When validation runs on blur, this behavior hijacks the user's natural tab navigation and moves focus to the first invalid field instead of the next field in the tab order.

How?

Call reportValidity() only when the invalid input remains the active element by checking:

inputElement.ownerDocument.activeElement === inputElement

This ensures the validation UI is still shown while preventing focus from being stolen during tab navigation.

Testing Instructions

  1. Run Storybook locally:
    npm run storybook:dev

  2. Open the DataForm validation story:
    DataViews → DataForm → Validation

  3. Set the layout to card-collapsible.

  4. Clear the Text field so it becomes invalid.

  5. Click inside Textarea.

  6. Press TAB.

Expected result:
Focus follows the natural tab order (Text → Textarea → Select / Password) instead of jumping back to the first invalid field.

Testing Instructions for Keyboard

  1. Navigate through the form using only the TAB key.
  2. Ensure that focus moves sequentially through fields even when validation errors exist.
  3. Verify that validation messages still appear without interrupting keyboard navigation.

@Shekhar0109 Shekhar0109 requested a review from getdave as a code owner March 26, 2026 15:04
@github-actions github-actions bot added the [Package] Block editor /packages/block-editor label Mar 26, 2026
@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block editor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

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: Shekhar0109 <shekh0109@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: NeosinneR <neosinner@git.wordpress.org>

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

@mcsf
Copy link
Copy Markdown
Contributor

mcsf commented Mar 27, 2026

Hi,

This PR doesn't do what it purports to do, doesn't fix the problem, and sidesteps the ongoing conversation on how to best approach it.

I'll close this to keep contributors' efforts focused.

@mcsf mcsf closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataForm: Validation on blur hijacks focus from the natural tab sequence in card layout

2 participants