Skip to content

Conversation

@jameskoster
Copy link
Contributor

I'm not sure how this got overlooked, but this PR is a small follow-up to #72249 which ensures the "LayoutCard" DataForm story uses the card layout to ensure correct spacing between cards.

Testing

Compare http://localhost:50240/?path=/story/dataviews-dataform--layout-card with https://wordpress.github.io/gutenberg/?path=/story/dataviews-dataform--layout-card and note that the gap between cards in the former is 24px compared to 16px in the latter.

@github-actions
Copy link

github-actions bot commented Dec 2, 2025

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: .

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

github-actions bot commented Dec 2, 2025

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: jameskoster <[email protected]>
Co-authored-by: oandregal <[email protected]>

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

@jameskoster jameskoster added [Type] Enhancement A suggestion for improvement. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Dec 2, 2025

const form: Form = useMemo(
() => ( {
layout: { type: 'card' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 This should not be necessary because every field declares its layout, and all the 3 top-level fields that create a card have card as the layout. That should be enough to match any styles. I'll take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

In case it's not clear, this is about the spacing between the cards themselves (which should be 24px), not the fields within the cards (which should be 16px).

Copy link
Member

@oandregal oandregal Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrapper layout depends on the form.layout.type. If not present, we normalize it to the regular layout that uses 4 as spacing setting, while the card layout uses 6 (ref).

This is fragile. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it was the individual fields (each card, each panel, each regular field) that set the spacing? Something along these lines:

  <div class="container">
    <div class="card">...</div>
    <div class="panel">...</div>
    <div class="regular">...</div>
  </div>
// DataForm CSS
  .container {
    display: flex;
    flex-direction: column;
  }

// The card layout's CSS
  .card + * {
    margin-top: 24px;
  }

// The panel layout's CSS
  .panel + * {
    margin-top: 16px;
  }

// The regular layout's CSS
  .regular + * {
    margin-top: 8px;
  }

Would there be any issue with this? We could remove all the wrappers from the existing layouts but the row one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think something along those lines might work. I made a CodePen to explore. The rules are a bit more specific to account for specific order combos but I think this covers everything neatly.

Do you think there are any trade-offs to using margin vs gap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oandregal any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've approved this PR, but we can continue the conversation.

I thought about this, but I've noticed we mix panel and regular items in a few places (QuickEdit, for example). If the field themselves provide the spacing, and each layout has its own, wouldn't this create different spacing between fields in the same form?

Copy link
Member

@oandregal oandregal Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought is that we make it a card because we want the spacing of a card. The spacing applied between fields is overloaded with the layout type. A different approach could be 1) remove the top-level layout prop, it's the field responsibility to declare its own 2) and a top-level gap prop to configure the spacing between fields.

If we go this route, I suppose the best approach would be to connect this gap with the spacing from DS (e.g., "xs", "md").

@oandregal oandregal merged commit e900161 into trunk Dec 23, 2025
51 of 56 checks passed
@oandregal oandregal deleted the update/dataform-card-story-layout branch December 23, 2025 16:32
@github-actions github-actions bot added this to the Gutenberg 22.4 milestone Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants