-
Notifications
You must be signed in to change notification settings - Fork 31
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
Make sidebar container scroll internally #554
Conversation
b9309f7
to
48fee8f
Compare
8bc9f39
to
f01b836
Compare
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.
Tested all the cases suggested in the description. Works as expected 👍
Left some comments, but none of them are blockers.
margin-top: 0; | ||
.is-link-to-top { | ||
display: block; | ||
padding-top: var(--wp--preset--spacing--20); |
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.
margin-bottom: 0 !important; | ||
padding: var(--wp--preset--spacing--20) 0; | ||
|
||
main & { |
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 seems to be the cause of this issue for me— this isn't sass, so the nesting rules aren't the same. This seems to be ignored by postcss, and then stripped out by cssnano, so the rules below are applied to all .wp-block-wporg-sidebar-container
s. I don't know why it works for you & @renintw though.
If I move this code to a new section main .wp-block-wporg-sidebar-container {…
it works as expected.
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 don't know why it works for you & @renintw though.
Nice catch! All this seems to work with a dev build, but it all breaks with a prod build. Starting to think moving to one CSS style would be a really good idea as switching feature sets contributes to this sort of issue. I think that was suggested to be postcss.
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 that was suggested to be postcss.
I think that was before wp-scripts natively supported sass… and maybe if we switched to sass here, we could remove the custom build script here.
My expectation is that the user would do the default and start scrolling the page, as they wouldn't expect the Chapter List to scroll until that behaviour is observed. Block.editor.chapter.scroll.mp4Make sense? |
I see your idea. Thanks for the explanation with the screencast👍 |
1f0b446
to
75ef37e
Compare
Co-authored-by: Kelly Dwan <[email protected]>
Co-authored-by: Kelly Dwan <[email protected]>
75ef37e
to
f5c8a52
Compare
This allows individual containers to become inline at different breakpoints, eg. the Chapter List remaining fixed and scrolling when the ToC is already displayed inline.
fbdf21b
to
0b9b873
Compare
In order for the Chapter List container to be fixed and scrolling while the ToC container is inline, the fixed styles have been decoupled from a specific breakpoint and managed via a class instead. The breakpoint for each container to switch between inline and fixed/floating can now be configured via a block attribute. In making this solution work on iPads in particular, I found that the change in the heights of the admin bar and global nav, and the sticky behaviour of the local nav bar and admin bar make for very complex calculations. A resize handler has been added to set some these changing variables on load, and update on resize to keep everything in sync. A such you should also be able to test switching orientation, not only page load. These changes can be viewed in b24b6f2. |
@media (min-width: 890px) { | ||
/* stylelint-disable selector-id-pattern */ | ||
#wp--skip-link--target { | ||
scroll-margin-top: var(--wp--custom--local-navigation-bar--spacing--height, 0); | ||
} | ||
} | ||
|
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.
Moved from the sidebar container styles, as it relates directly to the change in positioning of the local nav bar
9de411f
to
17d0add
Compare
// If there is no table of contents, hide the heading. | ||
if ( ! document.querySelector( '.wp-block-wporg-table-of-contents' ) ) { | ||
const heading = document.querySelector( '.wp-block-wporg-sidebar-container h2' ); | ||
heading?.style.setProperty( 'display', 'none' ); | ||
} |
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.
Moved to the render
Completes the states and fixes issues in Firefox
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.
Two pretty minor notes, but overall this is working well in my testing.
I did notice a bit of glitchy behavior when the content is shorter than the Chapters list, and the screen size is just tall enough to render chapters without scrolling, in this case ~1000-1100ish. The sidebar bounces back and forth between scroll/static.
scroll-glitch.mp4
Marking this as approved, if you'd rather fix in a follow-up PR.
esc_html__( '↑ Back to top', 'wporg' ) | ||
) | ||
: ''; | ||
$inlineBreakpoint = $attributes['inlineBreakpoint']; |
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.
$inlineBreakpoint = $attributes['inlineBreakpoint']; | |
$inline_breakpoint = $attributes['inlineBreakpoint']; |
PHP variables should be snake case. It looks like we're not running phpcs in the github actions, but you can run it locally with composer lint mu-plugins/blocks/sidebar-container mu-plugins/blocks/table-of-contents
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 in 2aed927
// If there is no content, don't render the heading. | ||
$content .= empty( trim( wp_strip_all_tags( $post_content ) ) ) | ||
? '' | ||
: do_blocks( | ||
'<!-- wp:heading {"style":{"typography":{"fontStyle":"normal","fontWeight":"400"},"spacing":{"margin":{"top":"0","bottom":"0"}}},"fontSize":"normal","fontFamily":"inter"} --> | ||
<h2 class="wp-block-heading has-inter-font-family has-normal-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:400">' . esc_html( $title ) . '</h2> | ||
<!-- /wp:heading -->' | ||
); |
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.
Shouldn't the if ( ! $items )
check prevent the entire block (incl heading) from being output? I know this is coming from the previous JS, but I'm not sure how we'd end up in a situation where empty( trim( wp_strip_all_tags( $post_content ) ) )
is true but ! $items
is false.
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.
Nice catch, I moved the logic without checking what would happen just removing the JS. Works just as you described, reverted the render change in 07b512c
… render" This reverts the render changes in commit 740a0aa, but keeps the JS changes
This adds space between sidebar and footer when main content is short
See WordPress/wporg-developer#453
This PR modifies the sidebar container so that once it becomes fixed, it also scrolls internally. When the footer collides with the bottom of the sidebar, the sidebar reduces in height rather than starting to scroll with the page.
It has been decoupled from the Table of Contents so that it can be used for the Developer Chapter List as well. JS changes are required to enable handling multiple sidebar containers on the page.
The scrolling areas have custom scrollbars so that they appear on hover. This has been inspired by the React docs (example), and should help users discover that these are scrollable more easily. With the typical Mac OS setting of hidden scrollbars, it is not immediately obvious. Note that this does not work in Firefox.
Overall this is a much simpler implementation, with no top positioning required, and no listener for
main
height changes.Testing
The Sidebar Container is currently used on Developer Resources and Documentation.
Things to test
Use WordPress/wporg-developer#447 to test Developer Resources
Documentation requires no changes, so you can use that local environment as is, and switch the mu-plugins install to this branch.