Discourse Dynamic Sidebar Icon

Install this theme component

:woman_technologist:t2: Summary

A lightweight Discourse theme component that dynamically changes the header’s sidebar toggle icon based on whether the sidebar is open or closed.

By default, the component displays the standard hamburger menu icon (bars) when the sidebar is closed, and transitions to a close X icon (xmark) when the sidebar is open.

Admins can specify custom icons instead if they wish, and also choose to enable for mobile view (while the dynamic aspect of the component only applies to non-mobile viewport sizes, admins that change the open icon may want consistency with their mobile UX).


:star: Features

  • Gives users clear visual feedback on how to interact with the sidebar.
  • Admins can easily replace the default icons with any FontAwesome icon via the theme settings.
  • Allows enabling a replaced sidebar icon for mobile viewport UX consistency.

:movie_camera: Video Screenshots

Component defaults:

Using dog and cat icons:


:wrench: Settings

Customize the icons used for opening and closing the sidebar by editing the component’s settings:

setting description
Icon_to_open_the_sidebar the icon displayed when the sidebar is collapsed
(default: bars)
Icon_to_close_the_sidebar the icon displayed when the sidebar is expanded
(default: xmark)
Apply_open_icon_on_mobile apply the custom ‘open’ icon on mobile viewport
(default: false)

:warning: Important Notes

  • If using custom icons that aren’t already included in core Discourse, they will appear blank; to fix this, you must add the custom icons (e.g., rocket, cat) to the SVG icon subset site setting in your Discourse admin settings (see All Site SettingsSVG icon subset).
  • This component does not work with header drop down mode.
11 Likes

I have refactored the component and added a new boolean setting Apply open icon on mobile (default is disabled). This is so that admins that change the open icon from the default bars can choose to enable it on mobile viewport size for UX consistency. The mobile overlay sidebar behaves differently, so the icon doesn’t change when the sidebar is activated in small viewport size. I have updated the OP as well.

2 Likes