Skip to content
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

Fix: Widget formatting #120

Merged
merged 2 commits into from
Oct 27, 2023
Merged

Fix: Widget formatting #120

merged 2 commits into from
Oct 27, 2023

Conversation

rise-erpelding
Copy link
Contributor

@rise-erpelding rise-erpelding commented Oct 26, 2023

Description

This PR makes some changes to the markup around the content block in order to resolve a bug that prevented the .obj-width-limiter class from centering/spacing content on the page appropriately when the sidebar widget is active. It also refactors how h1 tags are added to the page, in order to push the sidebar below the h1 for all pages.

Finally, this PR also adds a minor fix to prevent empty img tags from showing on the post page if there is no featured image added.

Closes #119

To Validate

  1. Make sure all PR Checks have passed
  2. Pull down this branch
  3. Run npm start
  4. Without widgets activated 1, view the following pages, they should appear the same as before (on main):
  5. Now activate sidebar widget (go to Appearance > Widgets, navigating here should automatically fill the sidebar with widgets), and view the same pages listed above. Post and sidebar should both align with the h1, header, and footer on the left side. Sidebar should appear in the same place on every page.
  6. Review the added documentation for accuracy, utility, and clarity.

Footnotes

  1. Fun fact: I learned today that you can deactivate the sidebar (or any) widgets but keep them around to bring them back easily by going to the list view in the widgets admin, and dragging the widgets in the sidebar area to the Inactive widgets area (shift-select or command-A to grab all widgets). I wrote about this in the documentation because it’s not obvious and prior to this I was wiping my database every time I wanted to take the widgets out, but it’s worth mentioning here for easier validation.

@rise-erpelding rise-erpelding marked this pull request as ready for review October 26, 2023 19:25
Copy link
Contributor

@dustin-jw dustin-jw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are a couple opportunities to simplify this a bit, but it works as intended!

@@ -24,6 +24,8 @@
$templates = array( 'index.twig' );
if ( is_home() && ! is_front_page() ) {
$context['title'] = single_post_title();
} elseif ( ! $context['posts']->found_posts ) {
$context['title'] = 'Nothing found';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary since the 404.twig template hard-codes "Nothing found" in its h1?

Copy link
Contributor Author

@rise-erpelding rise-erpelding Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the "Nothing Found" text that was removed in content-none.twig, which we include in the 404.twig template, but also in index.twig. It shows up if you have no posts, which is an edge case for sure. Leaving it off, it shows the text "Recent Posts" which isn't exactly accurate, but again, it's an edge case that would only occur if you didn't have posts, which isn't what people generally use WordPress for, so we could clip it out of here. I realized the capitalization for this didn't match all the others so updated it in ac7e974.

{{ function('get_search_form') }}
</div>
</section>
<div class="util-full-width">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a class for util-full-width, it might make more sense to apply margin-inline-start: auto to .cmp-primary-sidebar. This should push it to the right side of the page without requiring any interventions in the main content area.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 The property I never knew I needed. Thanks!

Copy link
Contributor

@dustin-jw dustin-jw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found another trivial, non-blocking thing that could be adjusted, but I'm happy to approve as-is!

@@ -1,6 +1,7 @@
.cmp-primary-sidebar {
background-color: var(--gray-background-color);
padding: 1rem;
margin-inline-start: auto;

@media (min-width: 50rem) {
flex-basis: 18.75rem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, with certain types of content in the sidebar, it can get squished down pretty small, so I'd recommend adding flex-shrink: 0 in addition to the flex-basis on wider screens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the media query like this? db6df75

Also moving that margin-inline-start inside the mq because we don't want the sidebar scooted over for small screens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, perfect! 🚀

- use title block for h1 elements to consistently position sidebar
- add documentation for widgets
- adjust positioning for 404 page and other pages where flex-sibling
doesn't occupy full width
Fixes a bug from the featured image work that checks to see if there is
an image first before adding an image tag to the document.
@rise-erpelding rise-erpelding merged commit 2826c6a into main Oct 27, 2023
2 checks passed
@rise-erpelding rise-erpelding deleted the widget-formatting branch October 27, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjust formatting when sidebar widget is enabled
2 participants