-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add no results placeholder in Query block #25984
Conversation
Size Change: +25 B (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
Eventually this should be customizable with an inner-blocks area. |
@@ -97,6 +98,10 @@ export default function QueryLoopEdit( { | |||
); | |||
const blockProps = useBlockProps(); | |||
|
|||
if ( ! posts?.length ) { | |||
return <div { ...blockProps }> { __( 'No results found.' ) }</div>; |
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 the blockProps in the div? Also could we just turn it into a p
tag for now?
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 the block wrapper. Every block needs at least one element that can act as the block wrapper with all events and attributes attached, otherwise it wouldn't be possible to interact with it and have no toolbar. This block is a light block, so it's responsible for rendering its own wrapper. The block cannot be just a string.
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.
But it would be a p
tag, sure. It can be any tag or component.
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.
We need it to mark it as a block
. If it was just a string
it wouldn't be selectable and interactive in general. I will make it a p
.
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.
Got it, I didn't review the broader context :)
Description
This PR adds to Query block a simple for now placeholder, when no results are found. This is needed because if no results are found and no other blocks exist, it shows nothing. Better design if needed will be in a follow up.