Skip to content

Commit 5846575

Browse files
jhashclaude
andauthored
Add mobile-friendly sidebar with hamburger menu (#11)
- Added hamburger button in navbar for mobile screens - Implemented slide-in/slide-out sidebar animation - Set fixed sidebar width of 16rem - Added ARIA attributes for accessibility - Added overlay for mobile sidebar - Made sidebar responsive with lg breakpoint - Added screen reader only class for accessibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent f19593a commit 5846575

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

app/assets/stylesheets/application.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,28 @@
88
*
99
* Consider organizing styles into separate files for maintainability.
1010
*/
11+
12+
/* Mobile Sidebar Styles */
13+
#sidebar-menu {
14+
width: 16rem; /* Fixed width of 16rem */
15+
}
16+
17+
/* Ensure main content adjusts on desktop */
18+
@media (min-width: 1024px) {
19+
main {
20+
margin-left: 0;
21+
}
22+
}
23+
24+
/* Screen reader only class */
25+
.sr-only {
26+
position: absolute;
27+
width: 1px;
28+
height: 1px;
29+
padding: 0;
30+
margin: -1px;
31+
overflow: hidden;
32+
clip: rect(0, 0, 0, 0);
33+
white-space: nowrap;
34+
border-width: 0;
35+
}

app/components/navbar_component.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
33
<div class="flex justify-between h-16">
44
<div class="flex items-center">
5+
<% if current_user %>
6+
<button type="button"
7+
class="mr-3 p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 lg:hidden"
8+
aria-haspopup="true"
9+
aria-expanded="false"
10+
aria-controls="sidebar-menu"
11+
onclick="document.getElementById('sidebar-menu').classList.toggle('translate-x-0'); document.getElementById('sidebar-menu').classList.toggle('-translate-x-full'); document.getElementById('sidebar-overlay').classList.toggle('hidden'); this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') === 'false' ? 'true' : 'false')">
12+
<span class="sr-only">Open sidebar</span>
13+
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
14+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
15+
</svg>
16+
</button>
17+
<% end %>
518
<%= link_to "Eight", root_path, class: "text-xl font-bold hover:text-gray-300 transition-colors" %>
619
</div>
720

app/components/sidebar_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<aside class="bg-gray-800 text-white w-64 min-h-screen flex flex-col" role="navigation" aria-label="Main navigation">
1+
<aside id="sidebar-menu" class="bg-gray-800 text-white min-h-screen flex flex-col fixed lg:static inset-y-0 left-0 z-40 transform -translate-x-full lg:translate-x-0 transition-transform duration-300 ease-in-out" role="menu" aria-label="Main navigation">
22
<div class="px-4 py-6">
33
<nav class="space-y-1" role="tree">
44
<% nav_items.each_with_index do |item, index| %>

app/views/layouts/application.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
<div class="flex min-h-screen">
2929
<% if logged_in? %>
30+
<!-- Mobile sidebar overlay -->
31+
<div id="sidebar-overlay"
32+
class="fixed inset-0 bg-gray-900 bg-opacity-50 z-30 hidden lg:hidden"
33+
onclick="document.getElementById('sidebar-menu').classList.remove('translate-x-0'); document.getElementById('sidebar-menu').classList.add('-translate-x-full'); document.querySelector('[aria-controls=sidebar-menu]').setAttribute('aria-expanded', 'false'); this.classList.add('hidden');">
34+
</div>
35+
3036
<%= render SidebarComponent.new(
3137
current_user: current_user,
3238
current_path: request.path,

db/schema.rb

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)