Skip to content

Commit bab8c5a

Browse files
committed
Sidebar container: Fix sticky scrolling behaviour
Recent changes to the global header and footer caused the floating sidebar containers on Dev Hub and Docs to not become sticky when scrolling. This commit adjusts the sticky position, and makes the footer element selector more robust, using a classname rather than a tagname.
1 parent adbb562 commit bab8c5a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

mu-plugins/blocks/sidebar-container/postcss/style.pcss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
/* Account for local nav height on larger screens where it becomes fixed. */
99
@media (min-width: 890px) {
10-
--local--nav--offset: 0;
1110
--local--offset-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wp--custom--local-navigation-bar--spacing--height, 60px));
1211
}
1312

mu-plugins/blocks/sidebar-container/src/block.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"title": "Sidebar Container",
66
"icon": "align-pull-right",
77
"category": "layout",
8-
"description": "A sticky container to be used in 2-column layouts.",
8+
"description": "A sticky container to be used in column layouts.",
99
"textdomain": "wporg",
1010
"attributes": {
1111
"hasBackToTop": {

mu-plugins/blocks/sidebar-container/src/view.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ let containers;
22
let main;
33
let footer;
44
let adminBarHeight;
5-
let globalNavHeight;
65
const scrollHandlers = [];
76

87
/**
@@ -46,7 +45,7 @@ function createScrollHandler( container ) {
4645

4746
// Toggle the fixed position based on whether main has reached the local nav.
4847
// This assumes that main and the sidebar are top aligned.
49-
const shouldFix = mainTop <= globalNavHeight + localNavHeight;
48+
const shouldFix = mainTop <= localNavHeight + adminBarHeight;
5049
container.classList.toggle( 'is-fixed-sidebar', shouldFix );
5150

5251
// If the sidebar is fixed and the footer is visible in the viewport, reduce the height to stop overlap.
@@ -72,7 +71,6 @@ function onResize() {
7271
window.getComputedStyle( document.documentElement ).getPropertyValue( 'margin-top' ),
7372
10
7473
);
75-
globalNavHeight = getCustomPropValue( '--wp-global-header-height' ) || 90;
7674

7775
containers.forEach( ( container ) => {
7876
// Toggle the floating class based on the configured breakpoint.
@@ -88,10 +86,14 @@ function onResize() {
8886
scrollHandlers.forEach( ( handler ) => handler() );
8987
}
9088

89+
/**
90+
* Initialize the sidebar container.
91+
* Three elements are required: main, a sidebar container (or multiple), and a footer.
92+
*/
9193
function init() {
9294
main = document.querySelector( 'main' );
9395
containers = document.querySelectorAll( '.wp-block-wporg-sidebar-container' );
94-
footer = document.querySelector( 'footer.wp-block-template-part' );
96+
footer = document.querySelector( '.wporg-footer' );
9597

9698
if ( main && containers.length && footer ) {
9799
containers.forEach( ( container ) => {

0 commit comments

Comments
 (0)