Collapsible sidebar

The collapsible sidebar layout is a variation of the sidebar layout that adds a toggle button to collapse the sidebar.

Installation

To install the collapsible sidebar layout, run the following command:

Copy
rails g instrumental:layout --collapsible_sidebar

Collapsible Sidebar Structure

While the collapsible sidebar looks very similar to the sidebar layout (and much of its' structure is the same), there are a few key differences:

  • It implements collapsible_sidebar_controller.js Stimulus controller to handle toggling open and collapsed states of the sidebar.
  • The Tailwind CSS classes that are applied to the navigation links (via the global _nav.html.erb partial) are quite different, as they are designed to handle both the collapsed and open states.

Toggling the sidebar

The sidebar can be toggled using the toggle button seen at the top of the sidebar.

The user's collapsed state is "remembered" since the collapsible_sidebar_controller.js Stimulus controller saves the state to the browser's local storage.

Instrumental Components

I created Instrumental Components to make designing and building professional apps with Ruby on Rails easy, fast, and fun. I use it on all of my projects and I hope it helps you build something great.

Brian Casel
Brian Casel
Creator of Instrumental Components
Learn more Send me a question or request