-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Gallery block: add gap support #37903
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a691007
Add gap support to gallery block
a5f39f7
Switch to using css grid so we don't need to recalculate image width …
aa2c19d
Revert "Switch to using css grid so we don't need to recalculate imag…
588f6a1
Add custom gap property to layout styles
3cbb53f
Add a scoped block gap css var to allow gallery to calculate image wi…
b6afcaf
Override the flex align-items setting
8adf044
Switch order of caption and media upload, and only render media uploa…
48a8b86
Improve naming of flex gap css var
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach, thanks, @glendaviesnz !
I see the need for block scoping in relation to gap support, and I believe it might help avoid the issues we saw in #36521
The only thing I'd raise as a potential issue is the coupling with the layout abstraction, that is, the requirement to opt-in to
__experimentalLayout
.If we look at this is as a feature to be used elsewhere, and not just the Gallery, I'd imagine some blocks might want to take advantage of a scope block gap CSS var, but I can also imagine that not all blocks would want to have the extra styles associated with the layout rules.
Not only that, I'd be interested to know whether it's sustainable to require theme developers to know that two support rules are required for scoped blockGap to work.
I don't know if these are legitimate concerns. The
gap
rule is a property of grid, flex, and multi-column layouts, which are..., well, "layouts" so there is that 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good questions - my reason for putting it there was that currently, you can't get
gap
support at all unless you opt intolayout
. It actually took a bit of time to get this PR started as I couldn't work out why the gap support wasn't showing when I had opted intospacing
🤔.I am guessing to move
--wp--style--scoped-block-gap
out oflayout
would require also movinggap
, which I assume would take a lot of rehashing of some previous decisions about why this is best placed inlayout
Layout does have some limitations I had to override in terms of the gallery, but I think these can be sorted in separate PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record - I'm having a related intellectual struggle about the role of layout in another PR: Experimenting with adding writing mode to layout #37932
There's an interesting discussion about a "styles engine", which, one day, might help with issues such as these.
I don't want to raise it as a panacea – we have immediate needs that might, for now, require some compromises such as the ones we're introducing in this PR – but I can easily envision that a centralized rendering engine might be the brain butter we need when making such decisions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi There! There are indeed interesting challenges here and I recommend you read through this PR a bit to understand the decisions about the coupling #37360 and why we want to avoid CSS variables as well.
--
Basically I have several concerns about this code:
--
If we're not able to find any solution without involving the CSS variable, I'd recommend a specific hook for the Gallery block to access its attribute (block gap) and generate the required styles without variables and independently of the "layout" block support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @youknowriad, that is useful feedback.
I think I have explored all the options for solving this without a css var, and haven't found a suitable alternative due to the fact that we have a variable number of columns and images, and require the uneven images to equally distribute on the last row, and due to the fact that the key style that needs to update is the width of the innerBlocks nested images, not the parent gallery block styles ... but I will take a look at using a custom hook and looking for a gallery specific solution rather than trying to solve this within the generic layout code.