Skip to content

Commit 4539497

Browse files
committed
Resolve scrollbar visibility on navbar on long content
This resolves #200, where a scrollbar was sometimes visible on the navbar. This unfortunately wasn't addressable with just CSS, as outlined in #206. Because we need the element to be scrollable, we can't set `overflow: hidden` on the nav element. This fixes this issue by: * Adding a `wy-side-scroll` element over the fixed position nav element and under the menu item elements * `wy-side-scroll` is set to 320px width, while the fixed position nav elements and menu item elements are 300px, clipping the scrollbar with `overflow-x: hidden` on the fixed position element * Javascript is set to scroll the new scroll element instead of the parent fixed position element * For backwards compatibility on already generated HTML, the new scroll element is added dynamically if it is missing, and children of the fixed position element are moved there. This was tested to be working in both cases on a variety of platforms: Linux FF, Chrome, Windows IE, OSX Chrome and Safari, iPhone 5.1, and Android 4.2.
1 parent 5e40211 commit 4539497

File tree

5 files changed

+65
-33
lines changed

5 files changed

+65
-33
lines changed

sass/_theme_layout.sass

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
padding: 0 $base-font-size
2525

2626
.wy-menu-vertical
27+
width: $nav-desktop-width
2728
header, p.caption
2829
height: $base-font-size * 2
2930
display: inline-block
@@ -164,13 +165,14 @@
164165
color: $white
165166

166167
.wy-side-nav-search
168+
display: block
169+
width: $nav-desktop-width
170+
padding: $gutter / 2
171+
margin-bottom: $gutter / 2
167172
z-index: $z-index-popover
168173
background-color: $link-color
169174
text-align: center
170-
padding: $gutter / 2
171-
display: block
172175
color: $section-background-color
173-
margin-bottom: $gutter / 2
174176
input[type=text]
175177
width: 100%
176178
border-radius: 50px
@@ -253,11 +255,18 @@
253255
padding-bottom: 2em
254256
width: $nav-desktop-width
255257
overflow-x: hidden
256-
overflow-y: scroll
258+
overflow-y: hidden
257259
min-height: 100%
258260
background: $menu-background-color
259261
z-index: $z-index-popover
260262

263+
.wy-side-scroll
264+
width: $nav-desktop-width + 20px
265+
position: relative
266+
overflow-x: hidden
267+
overflow-y: scroll
268+
height: 100%
269+
261270
.wy-nav-top
262271
display: none
263272
background: $link-color
@@ -342,6 +351,12 @@ footer
342351
&.shift
343352
width: 85%
344353
left: 0
354+
.wy-side-scroll
355+
width: auto
356+
.wy-side-nav-search
357+
width: auto
358+
.wy-menu.wy-menu-vertical
359+
width: auto
345360
.wy-nav-content-wrap
346361
margin-left: 0
347362
.wy-nav-content

sphinx_rtd_theme/layout.html

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,39 @@
8585

8686
{# SIDE NAV, TOGGLES ON MOBILE #}
8787
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
88-
<div class="wy-side-nav-search">
89-
{% block sidebartitle %}
88+
<div class="wy-side-scroll">
89+
<div class="wy-side-nav-search">
90+
{% block sidebartitle %}
9091

91-
{% if logo and theme_logo_only %}
92-
<a href="{{ pathto(master_doc) }}">
93-
{% else %}
94-
<a href="{{ pathto(master_doc) }}" class="icon icon-home"> {{ project }}
95-
{% endif %}
92+
{% if logo and theme_logo_only %}
93+
<a href="{{ pathto(master_doc) }}">
94+
{% else %}
95+
<a href="{{ pathto(master_doc) }}" class="icon icon-home"> {{ project }}
96+
{% endif %}
9697

97-
{% if logo %}
98-
{# Not strictly valid HTML, but it's the only way to display/scale it properly, without weird scripting or heaps of work #}
99-
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" />
100-
{% endif %}
101-
</a>
98+
{% if logo %}
99+
{# Not strictly valid HTML, but it's the only way to display/scale it properly, without weird scripting or heaps of work #}
100+
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" />
101+
{% endif %}
102+
</a>
102103

103-
{% include "searchbox.html" %}
104+
{% include "searchbox.html" %}
104105

105-
{% endblock %}
106-
</div>
106+
{% endblock %}
107+
</div>
107108

108-
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
109-
{% block menu %}
110-
{% set toctree = toctree(maxdepth=4, collapse=theme_collapse_navigation, includehidden=True) %}
111-
{% if toctree %}
112-
{{ toctree }}
113-
{% else %}
114-
<!-- Local TOC -->
115-
<div class="local-toc">{{ toc }}</div>
116-
{% endif %}
117-
{% endblock %}
109+
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
110+
{% block menu %}
111+
{% set toctree = toctree(maxdepth=4, collapse=theme_collapse_navigation, includehidden=True) %}
112+
{% if toctree %}
113+
{{ toctree }}
114+
{% else %}
115+
<!-- Local TOC -->
116+
<div class="local-toc">{{ toc }}</div>
117+
{% endif %}
118+
{% endblock %}
119+
</div>
118120
</div>
119-
&nbsp;
120121
</nav>
121122

122123
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

sphinx_rtd_theme/static/css/theme.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sphinx_rtd_theme/static/css/theme.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sphinx_rtd_theme/static/js/theme.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,23 @@ window.SphinxRtdTheme = (function (jquery) {
7474
}, 25);
7575
},
7676
init = function () {
77-
navBar = jquery('nav.wy-nav-side:first');
77+
// Because generated HTML will not immediately have the
78+
// new scroll element, gracefully handle failover by adding it
79+
// dynamically.
80+
navBar = jquery('div.wy-side-scroll:first');
81+
if (! navBar.length) {
82+
var navInner = jquery('nav.wy-nav-side:first'),
83+
navScroll = $('<div />')
84+
.addClass('wy-side-scroll');
85+
86+
navInner
87+
.children()
88+
.detach()
89+
.appendTo(navScroll);
90+
navScroll.appendTo(navInner);
91+
92+
navBar = navScroll;
93+
}
7894
win = jquery(window);
7995
},
8096
reset = function () {

0 commit comments

Comments
 (0)