-
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
Do not render Sections in Preferences modal if children render nothing #29207
Closed
Closed
Changes from all commits
Commits
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
35 changes: 22 additions & 13 deletions
35
packages/edit-post/src/components/preferences-modal/section.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
const Section = ( { description, title, children } ) => ( | ||
<section className="edit-post-preferences-modal__section"> | ||
<h2 className="edit-post-preferences-modal__section-title"> | ||
{ title } | ||
</h2> | ||
{ description && ( | ||
<p className="edit-post-preferences-modal__section-description"> | ||
{ description } | ||
</p> | ||
) } | ||
{ children } | ||
</section> | ||
); | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { renderToString } from '@wordpress/element'; | ||
|
||
const Section = ( { description, title, children } ) => { | ||
const content = renderToString( children ); | ||
if ( ! content ) return null; | ||
return ( | ||
<section className="edit-post-preferences-modal__section"> | ||
<h2 className="edit-post-preferences-modal__section-title"> | ||
{ title } | ||
</h2> | ||
{ description && ( | ||
<p className="edit-post-preferences-modal__section-description"> | ||
{ description } | ||
</p> | ||
) } | ||
{ children } | ||
</section> | ||
); | ||
}; | ||
|
||
export default Section; |
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.
That is not great :) It's like we'll be rendering twice. Isn't there a more "data based" approach instead of using the elements?
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 :) - it doesn't feel right to me either but it seems that we cannot use some React API to know what
children
will render, so we can't use things likeChildren.count
etc..., unless there is something I'm not aware of.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.
Can't we do the check in the parent and not render Section at all?
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 are lot's of checks that would be duplicate then like
PostFeaturedImageCheck
,PostExcerptCheck
etc.. and doesn't seem good to me.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 see what you mean but it seems this is already how we do in the document sidebar isn't it?
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 tried to find a css solution but with no success. We could do it with has when available :).
Not really sure if this change worths to be included right now, since this seems to me like an unusual use case (to disable all panel leaving an
empty
of contents section).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.
It's worth revisiting the CSS approach after 3 years to provide the simple fix at least to the supported browsers.
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.
It seems the css solution has been implemented already :)
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'll close the issue then 👍🏻
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.
You did that already, thank you Nik!