Skip to content

Commit

Permalink
Disable sticky-sidebar on small viewports (#5985)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Sep 15, 2022
1 parent c7618ff commit 4fe15e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/features/sticky-sidebar.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#js-repo-pjax-container .pagehead ul.pagehead-actions {
.rgh-sticky-sidebar-enabled #js-repo-pjax-container .pagehead ul.pagehead-actions {
z-index: initial; /* This affects the social buttons. It seems to have no effect but it constantly causes trouble with other features. */
}

Expand Down
8 changes: 7 additions & 1 deletion source/features/sticky-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import observe from '../helpers/selector-observer';
import onAbort from '../helpers/abort-controller';
import calculateCssCalcString from '../helpers/calculate-css-calc-string';

const minimumViewportWidthForSidebar = 768; // Less than this, the layout is single-column

// The first selector in the parentheses is for the repo root, the second one for conversation pages
const sidebarSelector = '.Layout-sidebar :is(.BorderGrid, #partial-discussion-sidebar)';

Expand Down Expand Up @@ -45,7 +47,8 @@ function updateStickiness(): void {
const offset = calculateCssCalcString(getComputedStyle(sidebar).getPropertyValue('--rgh-sticky-sidebar-offset'));
sidebar.classList.toggle(
'rgh-sticky-sidebar',
sidebar.offsetHeight + offset < window.innerHeight,
window.innerWidth >= minimumViewportWidthForSidebar
&& sidebar.offsetHeight + offset < window.innerHeight,
);
}

Expand All @@ -65,6 +68,9 @@ void features.add(import.meta.url, {
pageDetect.isRepoRoot,
pageDetect.isConversation,
],
exclude: [
() => screen.availWidth < minimumViewportWidthForSidebar,
],
deduplicate: false,
init,
});

0 comments on commit 4fe15e0

Please sign in to comment.