For a while, I wanted a sidebar I could drop into an existing Xojo web app and set up in the Inspector. I wanted it to work on phones and make room for the rest of the page when it collapsed.
Collapse WebSidebar and your menu shrinks to a strip of icons down the side of the page. A table next to it, locked left and right, gets wider as soon as that space opens up. WebSidebar moves and resizes the controls you’ve placed directly on the page, using the locks you set in the IDE. You can skip the width calculations and the Resized handler. Make the browser window narrow enough and the same menu tucks into a drawer you can open with a tap.
The sidebar control uses the Bootstrap 5 classes and components Xojo already loads, right down to the badges and the drawer. It follows your app’s theme out of the box. If you want the selected item to pick up a brand color of its own, override the Bootstrap styles in your CSS under .xojo-sidebar.
To try it in your own app, import WebSidebar.xojo_code and drag the control onto a page. Paste this little menu into InitialValue in the Inspector.
<home> Overview
<folder> Projects
<settings> Settings
When someone clicks Projects, you get "Projects" in ItemPressed. Use that event to show the Projects page or switch to its panel.
If you want to see it in action first, run the demo and try clicking a group icon while the sidebar is collapsed. Its submenu pops out alongside it. Grab the open-source control and demo on GitHub.
Gabriel is a digital marketing enthusiast who loves coding with Xojo to create cool software tools for any platform. He is always eager to learn and share new ideas!
