Skip to content

Commit 83c8d7a

Browse files
committed
Change sidebar hiding strategy to avoid flickering on mobile devices
Previously, the sidebar was hidden with JavaScript on small viewports. This approach caused flickering when the page was loaded, especially on mobile devices. Now, the sidebar is hidden by default with the `hidden` attribute. On large viewports, we display the sidebar with JavaScript. This approach avoids flickering when the page is loaded, especially on mobile devices.
1 parent 78a84d1 commit 83c8d7a

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

lib/rdoc/generator/template/aliki/class.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%= render '_header.rhtml' %>
44
<%= render '_sidebar_toggle.rhtml' %>
55

6-
<nav id="navigation" role="navigation">
6+
<nav id="navigation" role="navigation" hidden>
77
<%= render '_sidebar_pages.rhtml' %>
88
<%= render '_sidebar_sections.rhtml' %>
99
<%= render '_sidebar_ancestors.rhtml' %>

lib/rdoc/generator/template/aliki/index.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%= render '_header.rhtml' %>
44
<%= render '_sidebar_toggle.rhtml' %>
55

6-
<nav id="navigation" role="navigation">
6+
<nav id="navigation" role="navigation" hidden>
77
<%= render '_sidebar_pages.rhtml' %>
88
<%= render '_sidebar_classes.rhtml' %>
99
</nav>

lib/rdoc/generator/template/aliki/js/aliki.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ function hookSidebar() {
158158
});
159159

160160
const isSmallViewport = window.matchMedia("(max-width: 1023px)").matches;
161-
if (isSmallViewport) {
162-
closeNav();
163161

162+
// The sidebar is hidden by default with the `hidden` attribute
163+
// On large viewports, we display the sidebar with JavaScript
164+
// This is better than the opposite approach of hiding it with JavaScript
165+
// because it avoids flickering the sidebar when the page is loaded, especially on mobile devices
166+
if (isSmallViewport) {
164167
// Close nav when clicking links inside it
165168
document.addEventListener('click', (e) => {
166169
if (e.target.closest('#navigation a')) {
@@ -176,6 +179,8 @@ function hookSidebar() {
176179
closeNav();
177180
}
178181
});
182+
} else {
183+
openNav();
179184
}
180185
}
181186

lib/rdoc/generator/template/aliki/page.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%= render '_header.rhtml' %>
44
<%= render '_sidebar_toggle.rhtml' %>
55

6-
<nav id="navigation" role="navigation">
6+
<nav id="navigation" role="navigation" hidden>
77
<%= render '_sidebar_pages.rhtml' %>
88
<%= render '_sidebar_classes.rhtml' %>
99
</nav>

lib/rdoc/generator/template/aliki/servlet_not_found.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<body role="document">
22
<%= render '_sidebar_toggle.rhtml' %>
33

4-
<nav id="navigation" role="navigation">
4+
<nav id="navigation" role="navigation" hidden>
55
<%= render '_sidebar_pages.rhtml' %>
66
<%= render '_sidebar_classes.rhtml' %>
77
</nav>

lib/rdoc/generator/template/aliki/servlet_root.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<body role="document">
22
<%= render '_sidebar_toggle.rhtml' %>
33

4-
<nav id="navigation" role="navigation">
4+
<nav id="navigation" role="navigation" hidden>
55
<div id="project-navigation">
66
<div id="home-section" class="nav-section">
77
<h2>

test/rdoc/generator/aliki_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_generate
228228
index = File.binread('index.html')
229229
assert_match %r{<html lang="en">}, index
230230
assert_match %r{<body role="document"}, index
231-
assert_match %r{<nav id="navigation" role="navigation">}, index
231+
assert_match %r{<nav id="navigation" role="navigation" hidden>}, index
232232
assert_match %r{<main role="main">}, index
233233
end
234234

0 commit comments

Comments
 (0)