-
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
query-pagination-next and previous: Changing the markup on the first and last pages of a pagination #36681
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @matiasbenedetto! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
This is working well for me but it would be good to have some designers eyes on it - I'm not sure about the Previous/Next Page text appearing when it doesn't do anything. cc @jasmussen @kjellr |
@@ -26,7 +27,13 @@ function render_block_core_query_pagination_next( $attributes, $content, $block | |||
if ( $pagination_arrow ) { | |||
$label .= $pagination_arrow; | |||
} | |||
$content = ''; | |||
|
|||
$wrapper_attributes = get_block_wrapper_attributes(); |
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.
This is already defined on line 23, do we need to call it again?
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.
$content = ''; | ||
|
||
$wrapper_attributes = get_block_wrapper_attributes(); | ||
$content = sprintf( |
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.
Should we escape the output here incase the user tries to insert something untrustworthy in the attribute? (https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping/)
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.
Given that its not escaped elsewhere in this file it's probably safe...
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.
Yep, I think so
} elseif ( 1 !== $page ) { | ||
$content = sprintf( | ||
} else { | ||
$content = 1 !== $page ? sprintf( |
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.
I think this goes against the brace style in the PHP guidelines: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/
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.
fixed :)
I would agree, the text makes it sound actionable when it isn't. I do recall Kjell having some trouble with aligning the three harmoniously in a container, and I imagine there might be a layout challenge if the 3rd one is removed entirely. |
I think it would make sense to have it with lowered opacity. Right now it's already a challenge to keep the 3 items in the same place with any given layout if one of them disappears completely on first/last page too. And with the class added here, theme developers have the chance to style those cases in their own way too. |
Yeah, having the text present but unclickable seems incorrect here, even if it's a lower opacity. The standard behavior around the internet is basically what we have already today: the text only shows up if it's possible to paginate in that direction. The issue we're trying to solve for here is just that we can't automatically center the page numbers if there are two items in this container. That's just not the way that |
The problem is that inside the pagination block only the query previous/next/numbers blocks are allowed, so you can't wrap them inside column blocks. |
Right, but that's theoretically something we could change if it is necessary. |
What if we use CSS grid? |
Yeah, this seems like an appropriate use case for |
Grid in terms of theme.json integration with corresponding UI is a bit backburnered and not something to consider. However it looks like the "Query Pagination" block ( |
I implemented the change suggested in my last comment with this commit: Results:
|
I like this solution. It would be good to get some input from someone from an accessibility perspective, although I'm not sure who to ask... |
What happens with this solution when you align the items to the left or to the right instead of using space between? |
This last case mentioned by @MaggieCabrera (the use of |
We could conisder mapping the flex controls to CSS grid styles without making the user aware that's what's happening... |
a86850d
to
257760b
Compare
I think that the latest 2 commits fix the remaining problem around left and right
|
e7d88c5
to
64fe5b9
Compare
The latest commits are fixing some failing use cases, as the last one spotted by @scruffian. |
I no longer see the empty span on the first and last pages... |
This was an environment issue! |
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.
This is looking good to me. There's some duplication between the blocks that would be good to clear up in a followup PR.
$id = uniqid(); | ||
$style = gutenberg_get_layout_style( ".wp-container-$id", $used_layout, $has_block_gap_support ); | ||
$container_class = 'wp-container-' . $id . ' '; | ||
$justify_class = $used_layout['justifyContent'] ? 'wp-justify-' . $used_layout['justifyContent'] . ' ' : ''; |
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.
Why we added this to the layout
abstraction? Was something specific to pagination blocks?
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.
Yep, we needed to identify with a class the justification of the block, without this change that was not possible.
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.
There shouldn't be any block logic leaked into the layout
abstraction. I'll check a bit the PR better to try to understand. That was the case recently with Navigation
block as well, but we should find another way to handle specific block needs.
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.
Ok, I see, let me submit a PR with this change you propose.
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.
@ntsekouras a PR moving the functionality from Layout to Query Pagination code:
#37113
@@ -32,7 +32,17 @@ $pagination-margin: 0.5em; | |||
} | |||
} | |||
|
|||
&.aligncenter { | |||
justify-content: center; |
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.
This shouldn't be removed. It was added here: #34739 as a fix for align center
.
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.
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.
I know, but we also support the center
alignment and is needed for backwards compatibility.
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.
@ntsekouras could you provide more context about backward compatibility related to this, please?
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.
Sure. Even if the align:center
achieves the same think with centered justification, we still support this alignment. So it cannot be removed because it has created a regression. You can check this on trunk by selecting align:center
and checking the front-end.
Even if we removed the align:center
option though and with a new block migration in place, we would still need to keep the css rule because the migrations run and update the blocks markup in the editor and then we have to also save to get the new markup in the post content. So for content with blocks that had align:center
but the migration was never applied, the content should look as before in the front end without and broken styles.
Makes sense? Please tell me to clarify anything from the above if you want.
); | ||
} elseif ( ! $max_page || $max_page > $page ) { | ||
$custom_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) ); | ||
$max_num_pages = $custom_query->max_num_pages ? $custom_query->max_num_pages : 1; |
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.
Why do we need this max_num_pages
logic? Previously it would enter this if
when it was a custom
query and it wasn't on the first page. So wouldn't a check about $page === 1
be enough? Am I missing something?
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.
This is necessary because if the query has no results $custom_query->max_num_pages
equals to zero. So the logic to know if there are multiple pages 1 < $max_num_pages
doesn't work without this.
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.
I'm sorry but I still don't get it. In Query Pagination Previous
we only care about whether we are on the first page or not, no? If we are on the first page, we don't have a link to show, but if we are not we always have a link. This is different from Query Pagination Next
where we have to recreate the query run from Query Loop
to know if we have a link for the next posts.
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.
Nope, we don't care only about if we are on the first page or not. We need to know if there are pages to paginate. If there are not pages to paginate should not render anything.
…requirements. This characteristic was introduced here: WordPress#36681 and currently it is only necesary for the Query Pagination block so we can move the functionality to the block's code to avoid adding extra logic to the Layout block support.
Aside my comments that I'm trying to understand the changes here, I'd really want to thank you @matiasbenedetto for your contribution and effort here! Really appreciate it that you have also opened a follow up PR 💯 |
I've created a follow up PR to discuss/check how to simplify things (now is WIP). |
👋 I noticed this PR when this notice was shown: but it made me look into the changes here. I tried to understand the added complexity, especially in the case of Personally the concept of adding an extra element (hidden wrapper) for design purposes seems a bit odd to me and I'm not really sure if this should be added in the first place. Would another kind of layout be a better fit for these blocks (even if it doesn't exist yet like Additionally it seems the Screen.Recording.2021-12-06.at.8.40.45.PM.movTo sum up, I think we should consider reverting this PR and see for alternative approaches that should properly fix the design issues we want. I'm worried that if we follow this path, we just hack our way around the root issue and add complexity in block logic and styles to accommodate cases like the The root issue for me is that using --cc |
Personally, I don't see how using CSS grid could make this better for users and theme devs. I haven't tested the vertical flex orientation in this component before. The fix for the vertical orientation requires a really tiny CSS change proposed in this PR. |
I haven't been keeping up to date on developments since this comment, but for what it's worth, I think reverting this would be fine for now. Two thoughts:
|
Thanks for the design and product perspective! They match my assessment of the situation and give me confidence to also recommend reverting. Especially since we're dealing with a non-must-have issue that can be handled downstream. /cc @matiasbenedetto @jeffikus |
It looks like the revert button isn't going to work on this one. |
Hi 👋
Description
This PR changes the rendering of
core/query-pagination-next
andcore/query-pagination-previous
for 2 "edge cases". These cases are when the user is navigating the first or last page of a paginated query. In these cases, we render a<span>
instead of nothing as we commonly do with the pagination numbers where the number matching the pagination's current number renders a<span>
instead of an<a>
.After the changes featured in this PR the expected behaviour is:
While navigating a first page of a pagination:
core/query-pagination-previous
renders a<span>
element instead of nothing.core/query-pagination-next
renders an<a>
element as always.While navigating a last page of a pagination:
core/query-pagination-previous
renders an<a>
element as always.core/query-pagination-next
renders a<span>
element instead of nothing.While navigating any page of pagination that is not the first or the last one:
core/query-pagination-previous
renders an<a>
element as always.core/query-pagination-next
renders an<a>
element as always.While navigating a page with a
core/query-pagination
block in place but no data to paginate:This is just a continuation of a work started by @MaggieCabrera
Why are we introducing this change?
The intention is to fix the problems around the use of
space-around
justification in the flex container of thecore/query-pagination
block as described in this issue (#34997).How has this been tested?
Tested with normal and inherit wp queries using Empty, TT1, and Blockbase themes.
Block code:
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).