Skip to content

Commit 952e370

Browse files
dvassalloclaude
andcommitted
Fix mobile sidebar not auto-closing when room selected
The video library revamp (#77) expanded toggle_class_controller.js with Library-specific features but removed the critical mobile UX behavior: auto-closing the sidebar when navigating to a room. On mobile, the sidebar takes full viewport width. When a user taps a room link, they expect to see the room content immediately, not a still-open sidebar overlay blocking the view. Fix: Listen for turbo:click events and close the sidebar on mobile (max-width: 120ch) when any link inside the sidebar is clicked. This restores the expected behavior while preserving all Library overlay functionality on desktop. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fd55bdb commit 952e370

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/frontend/controllers/toggle_class_controller.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ export default class extends Controller {
3434
'a.skip-navigation[href="#sidebar-toggle"]',
3535
)
3636
if (skipToMenu) skipToMenu.addEventListener("click", this._handleSkipToMenu)
37+
38+
// Close sidebar on mobile when navigating to a new page
39+
this._handleTurboClick = (event) => this.#handleTurboClick(event)
40+
document.addEventListener("turbo:click", this._handleTurboClick)
3741
}
3842

3943
disconnect() {
4044
document.removeEventListener("mousedown", this._handleDocumentPointer)
4145
document.removeEventListener("touchstart", this._handleDocumentPointer)
4246
document.removeEventListener("keydown", this._handleKeydown)
47+
document.removeEventListener("turbo:click", this._handleTurboClick)
4348
const skipToMenu = document.querySelector(
4449
'a.skip-navigation[href="#sidebar-toggle"]',
4550
)
@@ -134,4 +139,20 @@ export default class extends Controller {
134139
window.matchMedia("(min-width: 120ch)").matches
135140
)
136141
}
142+
143+
#handleTurboClick(event) {
144+
// On mobile (max-width: 120ch), close the sidebar when clicking a link inside it
145+
// This ensures the user sees the room content after selecting it
146+
if (window.matchMedia("(min-width: 120ch)").matches) return
147+
if (!this.element.classList.contains(this.toggleClass)) return
148+
149+
// Check if the clicked element is a link inside the sidebar
150+
const target = event.target
151+
const link = target.closest("a[href]")
152+
if (!link) return
153+
if (!this.element.contains(link)) return
154+
155+
// Close the sidebar
156+
this.element.classList.remove(this.toggleClass)
157+
}
137158
}

0 commit comments

Comments
 (0)