close
Skip to content

Refactor DataFormLayout: Introduce getWrapper function for improved l…#74978

Closed
gigitux wants to merge 2 commits intotrunkfrom
fix/layout-wrapper-logic
Closed

Refactor DataFormLayout: Introduce getWrapper function for improved l…#74978
gigitux wants to merge 2 commits intotrunkfrom
fix/layout-wrapper-logic

Conversation

@gigitux
Copy link
Copy Markdown
Contributor

@gigitux gigitux commented Jan 27, 2026

What?

Closes #74999

Refactor wrapper selection in DataFormLayout by extracting it into a getWrapper helper and clarifying fallback behavior when form.layout.type is missing or not resolvable.

Why?

The wrapper selection logic had become harder to follow and reason about. This change centralizes the decision in one place.

How?

Wrapper resolution now follows this order:

  1. Use as when provided.
  2. If form.layout.type is defined, use its registered wrapper, falling back to DEFAULT_WRAPPER.
  3. If form.layout.type is not picked (for example, it is undefined), use the first field’s layout wrapper, falling back to DEFAULT_WRAPPER.

This mirrors the existing layout defaulting during normalization: fields without an explicit layout inherit the form layout, and when the form layout is not picked, the first field effectively drives the layout. The wrapper fallback now follows the same approach.

Field layout components are unchanged and still selected per-field via getFormFieldLayout( formField.layout.type )?.component.

Testing Instructions

  1. Check the Card Layout Storybook.
  2. Ensure that the gap across the cards is 24px.
  3. Remove the layout: "card" from form object (
    layout: { type: 'card' },
    fields: [
    )
  4. Ensure that the gap across the cards is 24px.

…ayout handling (#74999)

* Added getWrapper function to determine the appropriate wrapper component based on layout and form.
* Simplified the logic for selecting the wrapper, enhancing code readability and maintainability.
@github-actions github-actions bot added the [Package] DataViews /packages/dataviews label Jan 27, 2026
@github-actions
Copy link
Copy Markdown

Flaky tests detected in 4736b3b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21405199806
📝 Reported issues:

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

Labels

[Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant