Repository navigation
File: Add flex layout and block gap supports - #82851
im3dabasia wants to merge 25 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: -513 B (-0.01%) Total Size: 8.58 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Should insert content using the global inserter in Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
9f7624e to
e71084d
Compare
jasmussen
left a comment
There was a problem hiding this comment.
Thank you, this is fantastic! The video is very compelling, and the File block will be substantially more useful because of this.
I left some questions on the code. The primary question is: do we need any CSS at all for this to land? What would happen if we didn't add any?
ciampo
left a comment
There was a problem hiding this comment.
I'm not necessarily the best reviewer on block development, left a few comments nonetheless
3a85ebf to
ea98300
Compare
|
Thanks @/ramonjd for spotting the editor margins, and @/jasmussen for the block gap input, between them, that's what sent me down this path. Trunk spaced this block with two margins, one on the button and one under the preview, and the flex layout cancels both. I first tried replacing them with a gap of my own, but that turned out to be the wrong place for it, so spacing is now handled by block gap support instead. The measurements that were in this comment described that earlier attempt, so they no longer apply. |
|
What I tried first was adding the gap directly in the block's CSS. That wasn't a good approach — because of specificity, the theme's styles and anything set on the block couldn't override ours. Wrapping it in |
|
Went ahead with block spacing support here rather than in a follow-up, and removed the gap rule entirely, the block now ships no spacing CSS at all. Checked on the front end that both the row and column values apply independently, and that a theme setting File block spacing wins over anything the block would do on its own. |
|
Hi @tellthemachines @ramonjd, just gently bringing this one back up. From the discussion above, the layout support itself seems like a useful addition, so the remaining question is how the spacing default should behave. I've laid out three options above with the trade-offs I found, and I'd really value your thoughts on which direction fits best, or whether there's an angle I've missed. |
|
Thanks for your patience on this one, @im3dabasia, and for laying the options out so clearly. Lots going on. I'm not sure, but the way you've explained it, option 1 seems to be the best of the bunch given there are precedents.
In relation to the concern above about preserving back compat in block themes, I assume they'll get the theme's gap instead, or That sounds like a reasonable trade off on the surface. A theme can opt into block gap like this, right? "styles": {
"blocks": {
"core/file": {
"spacing": {
"blockGap": "0.22em"
}
}
}
}I'll add a
I don't know, but my instinct is to leave it out for now to reduce complexity and the test surface for reviewers. It could be a follow up if required. Better to iterate on these things in my opinion.
@tellthemachines I tried to reproduce this, and I think it might be related to caching rather than this PR. If I delete the
Maybe it's because when switching to this branch the block's Could be wrong, and maybe it's about a specific classic theme... |
Thanks @ramonjd, that's really helpful, and no worries at all about the wait. Happy to go with option 1 then. And yes, Columns does the same thing, which is reassuring. So the order ends up, weakest to strongest:
NB: what this costs
Why not give block themes a default too? Defaults don't apply there. We could add it as a block style instead, and existing blocks would then keep their spacing everywhere. A theme's On your questions, both match what I measured:
Agreed, happy to revisit it separately if it comes up.
That would explain it. It shows up fine for me on classic themes. |
|
Hi @ramonjd @tellthemachines, thanks for the reviews so far! The branch is up to date with trunk, and the "Space between" case without a file name is now handled. I've added a short status at the top of the description too. @tellthemachines, does the option 1 trade-off for block themes work for you? @ramonjd, is there anything else you'd like to see before this is ready? |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for working through all the layout cases here @im3dabasia 👍
I've taken this for a quick spin and it seems the saved blocks remain valid and their alignment holds. My concern is around the spacing on existing content.
As discussed, with this PR, the gap in File blocks falls back to the theme's root block gap. That changes the spacing of every File block already on a site, in every theme. I don't think a layout support change should come with a visual change to existing content.
We can keep the layout support and trunk's spacing:
- Drop the
__experimentalDefault. It adds a null placeholder that wipes any core value. - Set the block's default gap for
core/filein core's theme.json, like Icon in #75653. - Add the same gap to style.scss as
div:where(.wp-block-file) { gap: 1.3em 0.75em; }. Classic themes only get a zero specificity fallback gap, so this wins there and loses to any Global Styles gap.
Theme and user gaps still win, and existing content keeps its spacing.
|
Thanks @aaronrobertshaw. Agreed that adding a layout support shouldn't change how existing File blocks look, so I've applied your suggestion. Where it lands:
Trade-off
In summary, for developers and users
cc @ramonjd, since this replaces the direction we discussed earlier. PS:
|
|
Folks this was merged #86044 (thanks to Aaron for the quick review), now tests pass in this PR. This is ready for review. Open to reviews and feedbacks! TIA |
|
Hi team, After incorporating @aaronrobertshaw's feedback, this PR now handles backward compatibility much better, and I think the new block gap support is in a good place. Thanks for the reviews so far! Happy to address any remaining feedback. |
|
Rather than only deciding whether to merge this PR, I think it might be better to step back and discuss the overall direction first. My understanding is that one of the reasons this PR was submitted is the proposal in #19951 (comment): grouping File blocks together, and laying out the file name and the Download button with "space between".
In other words, this PR assumes that a new wrapper block for File blocks will be added. It's true that the File block lacks customizability, but as I mentioned here, I'm not very positive about introducing a wrapper block. I'm also hesitant about converting the File block to use inner blocks (see #57314 (comment)). If we decide not to introduce a wrapper block, I'm not confident that shipping this PR on its own would be worth it, when weighing the benefits against the cost of maintaining backward compatibility. I'd love to hear everyone's thoughts. |
|
Thanks, that's fair, and stepping back on the direction makes sense. You're right that the wrapper block was the main motivation for this PR. That said, I think it still helps a single File block on its own:
Since existing File blocks keep their spacing and alignment, the ongoing cost is a few small compatibility styles. If the consensus is that this isn't worth it without the wrapper, I'm happy to close it. Keen to hear what others think. |


What?
See #19951
Adds layout and block gap supports to the File block, so its content can be justified and its spacing themed.
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Trade-offs
Screenshots or screencast
file-block-shows-rich-text-field-on-selection.mov
Use of AI Tools
Claude Code