Motivation
I was missing the functionality to completely toggle away the toolbar.
Because on different projects i had different problems with the auto-pushdown if you have fixed elements in your layout or if you are developing and your debug output hides behind the toolbar and i just wanted to quickly check how it would look without the toolbar without loging out or open an inkognito-tab.
Implementation
It´s a "quick and dirty" js solution, which adds a key-combination (ctrl + alt + h) to hide and show the toolbar. It uses localstorage to save the current state. I´m using this solution and it works very good, so why not share it with you :-)
Tested with Oliviero and Claro and Gin with Gin-Toolbar.
PS: The latest development is within the issue-fork, not in the latest patch file
Remaining tasks
Put this into a submodule, so it is better isolated, optionally and probably preferred by the maintainers.- Have an indicator that your toolbar is currently not displayed somewhere.
- Add shortcut to Module shortcuts
| Comment | File | Size | Author |
|---|---|---|---|
| #73 | Screenshot from 2025-05-14 14-31-01.png | 29.34 KB | jatingupta40 |
Issue fork admin_toolbar-3304810
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
shyam_bhattI have checked the patch is working fine. Please check the below images.

Before applying the patch, when we open non-admin routes the "Toggle button" is not visible on the left top bar.
After applying the patch, when we open non-admin routes the "Toggle button" is visible on the left top bar. The button toggle functionality is also working fine.

Comment #3
shyam_bhattComment #4
sascha_meissnerComment #5
sascha_meissnerHey Shyam_Bhatt, thank you for testing.
That motivated me to make a little improve so that the toggle will adapt the background color of your toolbar-bar instead of just being red.
Just use the admin_toolbar__toggle_complete_toolbar_2.patch then.
Comment #6
vinaymahale commentedThe patch does not work properly for me on D9.4.5 and PHP 7.4.
On admin routes the toolbar looks like this:
On Non-Admin routes the toolbar shows like this:
On Non-Admin routes when the toggle button is clicked the toggle icon shows like this:
The toggle works properly but the background color of the toggle icon breaks.
Comment #7
vinaymahale commentedChanging to Needs work
Comment #8
sascha_meissnerHey vinaymahale
Thank you for testing. I try to make it compatible to olivero. Forgot to mention this in the initial post that its built on bartik
Comment #9
shyam_bhatt@vinaymahale I have updated the code. Please check the new patch.
Comment #10
vinaymahale commentedThank you @Shyam_Bhatt for the patch.
Before testing the patch, I'm setting it to "Needs work" so that the patch is re-submitted with a proper naming convention.
I encourage you to kindly have a look at the naming convention for a patch.
Here is a reference link for you to go through:
https://www.drupal.org/project/naming/git-instructions
Comment #11
shyam_bhatt@vinaymahale Please check the below patch:
admin_toolbar__toggle_complete_toolbar-3304810-11.patch
Comment #12
shyam_bhattComment #13
vinaymahale commentedThank you @Shyam_Bhatt for the patch.
I tested the toggle functionality. It works well, but there needs more enhancement.
The toggle remains open if I navigate to any menu links on the non-admin routes.
Steps to reproduce:
1. Install the module on an existing Drupal 9.x. site
2. Apply the patch from comment #11
3. Visit a non-admin route
4. Toggle to hide the admin toolbar
5. Then, Open a menu link of the site from the non-admin route
6. The toggle opens up and the admin toolbar is visible
7. Expected: the toolbar should not be visible since it was hidden in step 4
Changing to "Needs work"
Comment #14
vinaymahale commentedOnce the enhancement is done, can proceed with testing
Comment #15
shyam_bhatt@vinaymahale Once the page reloads the Toggle button will be in the initial state.
Comment #16
vinaymahale commented@Shyam_Bhatt By initial state, do you mean the admin toolbar remains open after every page reload (on the non-admin routes)?
That is how it works for me after applying the patch.
Comment #17
shyam_bhatt@vinaymahale Yes, The admin toolbar remains open after every page reload (on the non-admin routes).
Comment #18
shyam_bhattComment #19
sascha_meissnerFor me, the positionig in olivero is much better now.
But there is still issues on the positioning with the fixed / expanded header when scrolled and toolbar hidden / opened that still needs work.
Comment #20
sascha_meissnerThough i added a simple state storage so that
#13 7. Expected: the toolbar should not be visible since it was hidden in step 4
is working with patch 12 when localstorage is available, i also restructured code a bit so its more portable, but i dont think this feature is worth making it another js file or a submodule either.
Still there is work to make it compatible with oliviero see my comment above.
Comment #21
sascha_meissnersame patch as above but without the not removed console.log.
Comment #22
gaurav-mathur commentedComment #23
gaurav-mathur commentedPatch #11 applied successfully on on Drupal 9.4.5 and PHP 8.1.6.
The patch does not work properly for me.
After applying the patch I tested the toggle functionality.It works well,but i get symbolise at the place of arrow.
Refer to screenshots.
Comment #24
sascha_meissnerI´m not sure why this works for me and not for you.
Within the patch i use utf-8 symbols ▲ and ▼
Comment #25
vinaymahale commentedAny updates or work done here?
Comment #26
anybodyReally good and helpful idea! Especially when theming projects and you need to be logged in, but the admin toolbar should be toggled away. In mobile devices it's quite space-consuming.
So yes, would be nice to proceed here.
As a first step, the patch might be turned into a MR for easier review and merge?
Comment #27
sascha_meissnerThanks Anybody,
so what really needs to be done IMHO is to make it work properly with oliviero and probably also with gin admin theme. Besides that making it a MR seems to be a good step. I hope i can take a dive into this again soon, because on the sites i´m using this it´s actually very handy and on other sites where i dont/cant use this i find myself often in the browsers element inspector and remove the toolbar to see whats under it ... :)
Comment #28
sascha_meissnerComment #29
anybodyThanks, might also go into https://www.drupal.org/project/gin_toolbar - what do you think makes more sense? Or should you ask the admin_toolbar maintainers first, if they are interested in this feature?
Comment #30
handkerchief+1 for this feature! I've wanted that for a long time for the same reason as the author of this issue.
Comment #31
anybodyComment #32
sascha_meissnerThank you for the feedback :-)
This was my first try to contribute something when i started learning Drupal, it turned out to be more complicated than i thought due to the fact that admin-themes are variable and come with their own markup. Now two years later i´m thinking that it would still be a nice feature, gin-theme tried to adress it a little bit by putting stuff into the sidebar but still there is no way to also remove the top-bar. So what i am thinking of right now is that the toggling could be made with a keyboard-combination sth. like "shift + h" with no button at all, so there the whole problem-layer with positioning and styling the button would disappear. I´ll try to code something up when i have an oppurtunity/time :)
Comment #33
handkerchiefGreat! Until now, we have always had to solve this by creating a new role especially for this scenario, which is an unnecessary effort.
Comment #34
sascha_meissnerComment #35
sascha_meissnerComment #37
sascha_meissnerHey i just implemented what I was describing in my last comment.
You can now use the key-combination "Shift + H" to toggle the toolbar, IMHO this is working veeeery good, i like it very much, also my team does :P
Due to the fact that there is no css required anymore it just works, no matter if you use Claro or Oliviero or other theme. I also removed the differenciation between admin and non admin routes, because i didnt see the point anymore.
Also i created an issue fork and a mergerequest.
Please test and review my changes :)
Comment #38
sascha_meissnerComment #39
handkerchiefThank you very much for your work. But I am a bit confused. The toolbar on the left disappears, but:
- The padding on the left remains
- The toolbar at the top of the screen remains
Just the icons of the toolbar on the left are gone. I currently have zero benefit. The goal would be to be able to hide the admin areas in the frontend as if you were viewing the website anonymously. But the admin bars still disrupt the whole layout.
Comment #40
sascha_meissner@handkerchief, now I see what you mean... it works good for the "regular" admin-toolbar in bartik or oliviero, but it has issues on gin-theme i didnt test. Let me see if i can figure something out for gin
Comment #41
sascha_meissner@handkerchief Works fine now with gin as admin-theme and gin-toolbar as well :-)
Built in a little check if it´s gin and if so also hiding the "gin-secondary-toolbar--frontend" and correctly overwriting the paddings, this didnt work before because gin uses !important rules here, please review and test.
Comment #42
sascha_meissnerComment #43
handkerchief@sascha_meissner thank you very much, it's working now.
When hidden and when reloading, the page jumps because the toolbar is displayed first. This is due to the nature of the thing when the script is executed, so probably not much can be changed. In any case, a big step forward, thanks again.
Comment #44
sascha_meissnerComment #47
ressaThanks! Perhaps the "Implementation" section could include an image or two, based on the latest MR?
Comment #48
sascha_meissnerSry guys, i started this but didnt find the time to come back to finish.
IMHO there is two things left that need work
1. Put this into a submodule, so it is better isolated, optionally and probably preferred by the maintainers.
2. Have an indicator that your toolbar is currently not displayed somewhere.
Comment #49
ressaThank you for fast feedback @sascha_meissner, it's greatly appreciated. And I understand, things can get in the way. I have added the remaining tasks in the Issue Summary.
There is also the new feature of letting the menu stay at the top, which may help in some cases.
Comment #50
sascha_meissnerComment #51
sascha_meissnerThank you @ressa !
So i already putted this into a submodule for now :)
IDK whether this feature will ever make its way into the module, but personally i still like it and have the personal motivation to at least leave this clean because it´s the first contribution i ever created when i started with drupal :P
Comment #52
ressaNice thanks! The first contribution is always special :)
Comment #54
grevil commentedDid some minor adjustments. Generally works great and definitly helps! Great work @sascha_meissner!
Someone should take a final look at the CSS changes and test it with the gin theme active.
Furthermore, I am unsure if the current key combination of "ctrl + alt + h" will suffice for toggling the toolbar. Maybe we should add a small button somewhere, which toggles the toolbar?
At last, we should discuss, whether the current key combination feels the most DX friendly and document the key combination somewhere (probably in the tooltip of the toggle button)
EDIT:
Ah, and:
(#48)
Comment #55
grevil commentedComment #56
grevil commentedAlright, I changed the key combination to "Alt + h" (since the Key combo for admin toolbar search is "Alt + a" I thought "Alt + h" might be more in line.
Furthermore, I implemented the collapse / expand button. @thomas.frobieter will now begin for the final styling + remaining fixes.
After that, we can do a final DX discussion.
Comment #57
ressaThanks for all the efforts here! I have a few comments:
/admin/config/user-interface/admin-toolbar) below the new "Toolbar sticky behavior" and "Toolbar hoverIntent behavior" settings, which were just added ...Perhaps something like this?
As an ordinary user of Admin Toolbar, I would personally prefer to not get yet another "Admin Toolbar" module. Also it would make the list of modules under "Extend" (
/admin/modules) even longer ...Comment #59
thomas.frobieterOkay, I've added CSS + icons. I've also tested and fixed Gin, with its four toolbar styles.
Moved the .toolbar-expand-floating-button into body, because Gin hides #toolbar-administration in some situations.
I haven't checked smaller viewports / mobile yet.
I think we should not use hide(), show() and toggle() as function names in the JS file, as all three are jQuery functions, which is confusing. My naming is certainly not perfect yet either.
I am not sure about the settings.initial_toolbar_padding_top / settings.initial_toolbar_margin_left. What is the purpose of these settings? I am not a big fan of manipulating styles in JS. If possible, we should set classes instead and put the required CSS in admin_toolbar_toggle.css.
EDIT: Another note - due to the old CSS float technique, we cannot easily add the Hide Trigger button as the last element (visually). There are several outdated frontend techniques used by the admin toolbar. Gin has already fixed all of them, maybe it is a good idea to apply these styles some day.
Comment #60
ressaRestoring "Needs discussion" tag, sorry @Grevil :)
I thought it was a left over tag, but now see it was added yesterday ...
Comment #62
dydave commentedThanks a lot everyone for the great work on this issue, with the CSS, JS and icons! 😍
It really looks great, thanks a lot!
Based on the work in the previous merge request, I created the new merge request MR !146 above at #61 which suggests a different approach for the implementation of this feature:
The shortcut keys were changed in this MR 😅
How about
Alt + p? Could that work for you?I have a plugin/extension in my browser locally that is using
Ctrl + Alt + halready...So I thought we could maybe try with "Alt + p" ?
For the setting, I thought we could do something similar to #3494646: Access Admin Toolbar search field via keyboard shortcut Alt + a and add a setting in the recently added
Advancedsection of the settings form.Most of the work in MR !146 is around the CSS and JS logic:
Again, I thought we could maybe try to capitalize/build on top of what was done in #3509584: Add Show on scroll-up / Always hide option to Disable sticky toolbar and re-use the display/hide animation and states/classes that were already defined.
The JS code was refactored to use Vanilla JS, fix ESLINT errors and implement a logic toggling CSS classes in the 'body' tag of the page, based on the local storage.
All the CSS styles and images for the toggle links were moved from the previous merge request.👌
Unfortunately, in this first draft, support for the Gin Theme had to be dropped: 😖
I noticed the
'hide_on_scroll_down'sticky behavior doesn't work very well with the Gin theme as well, so I thought maybe we could potentially address the issues at the same time.Additionally, I "think" there is already quite a lot in this MR, so perhaps support for Gin for this feature should be part of a follow-up issue, maybe with a bit more generic approach? 😅
I would greatly appreciate to have your feedback and reviews on this new merge request, in particular, the shortcut key, the wording, labels, textual elements in general, the CSS/JS code and approach, etc...
Thanks in advance!🙂
Comment #63
ressaThanks @thomas.frobieter and @dydave! I agree with the solution in the latest MR, to include the feature inside Admin Toolbar module, and not as a separate module, to keep things simpler.
I also noticed the Gin-specific code, and handling Gin-specific solutions in a follow up issue seems like a good idea.
Perhaps the new feature could be placed on same level as "Toolbar sticky behavior" and "Toolbar hoverIntent behavior", below them, and not under "Advanced settings"?
Instead of "Toggle", it could be branded as the less ambiguous "Hide shortcut" to make it immediately clear what the feature does. "Toggle" is ambiguous, and could mean for example switching between a Light and Dark mode. The option could then be something like
[ ] Enable Hide shortcut (Alt + p)... But if everyone agree that "Toggle" is best, that's also totally all right :)Comment #64
thomas.frobieterEverything looks very good and clean to me now!
Alt+P works fine for me. I've added it to the title text of the toggle buttons!
+1 for this.
Comment #65
ressaHide vs. Toggle
About renaming from "Toggle" to "Hide", maybe it's too much work? I think we should at least visit the subject, and then decide if it's too much effort ...
My reasoning is this: "Toggle" means changing the state of something (like I already commented, see #63).
Think about the Link weight button. It is using these words in the GUI:
.. in the code you see this:
tabledrag-toggle-weight-wrapperBut the button doesn't say "Toggle", right?
Advanced
Also, I do think moving it up a level from "Advanced" could be considered (again, see #63).
Comment #66
dydave commentedThanks a lot @ressa as usual for the great help and feedback!
Thanks also Thomas (@thomas.frobieter) for the prompt and positive feedback on this updated merge request.
@ressa: No problem at all for all the suggested changes! 🙂
I have just moved the
'enable_toggle_shortcut'checkbox from the "Advanced" to the "Toolbar sticky behavior" ✅It certainly makes sense, at least from a code perspective, since the setting is using the same CSS as the
'hide_on_scroll_down'sticky behavior.I have also updated the checkbox label to:
Enable keyboard shortcut (Alt + p) to show/hide the toolbarand couldn't find any moretogglekeyword in the visible textual elements.Should we also change
toggleeverywhere else? Or could we still at least keep it, as it is currently, for the variable names and such?See for example, the name of the config:
enable_toggle_shortcutI think it "should" be fine to maybe keep it for variable names and in the code in general, as long as it is not visible by users and identifies clearly the feature for developers.
Otherwise, I've noticed we're using 'Alt + p' (lower case) in the form, but 'Alt +P' (upper case) in the JS code, see:
https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/146/di...
Are we fine keeping both? Or should we standardize with one of the two?
Feel free to send us more feedback, reviews and comments!
Thanks in advance! 🙂
Comment #67
ressaPure awesomeness @dydave, that's much better!
How about slimming down the label to this?
I think, that
togglecan stay "behind the scene" for example in variable names, it's the user facing part that's important.Though the config names perhaps should perhaps be updated from
enable_toggle_shortcuttoenable_hide_show_shortcut, since you could argue that config is also a sort of user facing component ... Or is it easier to update everything fromxyz_toggle_vartoxyz_hide_show_var? I'll let you be the judge :)About case, since we are using "Alt + key" (lower key) everywhere else, I think we should also use "Alt+p" here.
Comment #68
dydave commentedThanks again @ressa for the very clear and speedy reply!
OK, I've dealt with the simple changes, with the checkbox label and "Alt+p" (lower case) ✅
Concerning the variable name, this is a much bigger change 😅
enable_toggle_shortcutIndeed, the keyword
toggleis in all the names of the CSS/JS files, classes, functions and/or variable names in the JS code, etc... 😅Besides, I "think" the keyword "toggle" in terms of code, in this particular context, should be "legit", in the sense, it actually toggles (add/remove) CSS classes in the body tag of the page, from one state (visible) to another (hidden) and vice versa.
This is what the JS function toggle actually does:
https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle
Maybe we could change it to something like
toggle_display_shortcutortoggle_toolbar_shortcut?Or if you think
hide_show_shortcutcould work better, then I would also be fine with that 👌But in any case, if we were to make this change, we would better be 100% sure of the new name, since this is a pretty impactful change that could break quite a lot of things in this MR 😅
Moving back to Needs review for more feedback!
Thanks again! 🙂
Comment #69
dydave commentedOther questions:
1 - What about existing sites?
With the current MR, when existing sites upgrade to this feature, it will be disabled by default (since the setting does not exist, has not been initialized), until the settings form is saved.
Should the feature be enabled or disabled after upgrade?
@TODO: Missing implementation of
hook_update2 - Test with Sticky behavior disabled:
When hiding the toolbar, the icon stays fixed on screen, when the toolbar itself stays at the top of the page.
Do we want to make this behavior consistent by having the expand icon also stay at the top of the page (instead of following the scroll)?
Comment #70
ressaThanks @dydave, for fast updates! The update label reads great now, it's immediately clear what it does.
To update
toggle, or not: It's totally fine as it is then. The config variable is a minor detail, and probably understandable by most users. So let's keeptogglebehind the scene :)Behaviour with Sticky: I am fine with the current behaviour, but you could argue that it should slide away as well, if "Disabled, show on scroll-up" is selected. But I think it is fine as it is, especially if it takes a lot of work to tweak just right.
Enabled/Disabled/
hook_update: This feature could be considered fairly niche (I will probably never use it) so maybe it should actually be disabled by default? This would also mean that there is no need for ahook_update. I believe this is the last outstanding task to consider. (As a side note, the shortcut conflicts with a browser add-on I use.)Comment #71
dydave commentedSounds great @ressa! 👍
Thanks a lot once again for keeping this feature on track 😅
Indeed, if you still find any textual element related with this feature that should be changed, we would surely be glad to do so.
Otherwise, let's keep the variable names as they are for now 👌
I have just updated the merge request to:
Updated the Functional Tests accordingly and they all seem to still pass 🟢
Not sure what we could do for the shortcut though 😅
Would you have any suggestions of keys or ideas?
Other than that, I did another overall review of the code of the merge request and any potential conflict with other features, and at this point, we should be OK 👌
Back to Needs review for more testing, reviews and feedback on the latest changes.
Thanks in advance!🙂
Comment #72
ressaHi @dydave and right back -- thanks for implementing the feedback so fast, 21 May is getting closer 😅
Your updates look great, and the shortcut is disabled on install by default. Nice touch that the icon is now also sticky, if "Disabled" is selected. And great with the clean up, it is always a good idea to remove unused code, and that tests are still green!
I think the current shortcut is fine, it's a custom one I defined myself. At some point in the future, it could be considered to offer a predefined list of shortcuts in a drop-down, so that it would be selectable, where "Alt + p" could be the default, for example these?
But a drop-down feature is probably best saved for next version, so this feature is RTBC 🚀
PS. A tiny detail, which perhaps could be fixed here as well when committing, is that perhaps "Toolbar: sticky" could be updated to just "Toolbar sticky" (or something like that) without the colon symbol, in this string?
Comment #73
jatingupta40 commented@dydave I tried applying the patch but it didn't worked out.

I tried on Drupal v10.4.8.
Comment #74
ressa@jatingupta40 The patch applied fine when I tried it, as it should do, when it says "MR !146 mergeable". That literally means that the patch applies with the latest dev-version of the module ...
This is the method I use, and as the last command shows, there are no error messages, showing that the patch was applied:
Comment #76
adriancidThanks
Comment #77
dydave commented@ressa, thanks a lot for the very constructive and quick feedback, it's super appreciated! 🙏
Looks like we're going to have to be careful not to keep issues RTBC for "too" long in the issue tracker...
Otherwise they just might get abruptly merged 😅
Sorry I didn't have the time to make the suggested changes for the wording of the settings form before the MR got merged 😅
No worries: "Luckily" the 3.x build pipelines are now failing with PHPCS errors 🥳So I'll make sure the changes to the form are added in the next MR to be merged asap to fix the dev branch build pipelines 👌
Otherwise, once again, I personally think you have great UX and feature ideas: I like very much your suggestion of a dropdown list of suggested shortcuts to make it configurable 👍 (efficient, simple, clear)
We could immediately create this ticket (feature) and probably group it/do the same kind of implementation for the Search focus shortcut (#3087173: Allow shortcut keys to be configurable). Some tickets, in particular feature requests could already start getting planned for the following release.
Additionally, we still have a spin off/follow-up ticket to create for this one ==> Improve compatibility with the Gin theme.
We definitely want to keep the work from @thomas.frobieter specifically related to supporting GIN, mostly the CSS and JS files (MR!70).
We'll most likely end up adapting/keeping most of the code, probably organized a bit differently.
So that's already 3 or 4 new tickets on which we could start working for the following release 👍
Lastly, thanks a lot for taking the time to kindly explain to other contributors/users how to apply patches or help testing module's merge request and for all the kind words and encouragements in other issues.
Special thanks to @sascha_meissner for getting this issue started and @grevil and @thomas.frobieter for helping getting it over the line!🙏
Comment #78
dydave commentedraaaaa.... looks like it was a random build fail 😅
Retrying the PHPCS job came back green 🟢
So the pipelines actually seem fine.
Let's try to make this change to the form wording in the next MR 👌
Comment #79
grevil commentedAwesome! Thanks, @dydave and @ressa for your quick back 2 back finalization of this! 😍
Comment #80
ressaThanks @dydave for all the great work here in Admin Toolbar, you're doing a stellar job! And yes, that was a bit of an abrupt merge ... 😅
It would have been great to be able to do the final small tweaks in this MR, but it's a good idea to include them in the next MR
Thank you for the nice words about my suggestions, I just try to approach it from up above, and see it from the perspective of a regular user (such as myself) -- like, are the headings and features easily understood at a glance, is the interaction user friendly, etc.?
I know how you can easily focus on getting the code working, while forgetting about the user interface. In #3498980: Add date-only date formats, and use in Announcements Feed, it was only at the last minute, after @penyaskito luckily noticed that the order of dates could be improved, with better sorting, that it got fixed ... I had overlooked that they were jumbled up, since my focus was on navigating the GitLab UI, writing (unused) updates_hooks, etc. 🙂
So building Drupal is a team effort, where we all take on different roles at different times, and help each other out, however we can.
I like your idea about merging the shortcut issue into a "Meta" issue, where we can deal with both "Admin Toolbar Search" and the new "Hide Toolbar" feature. I have updated the shortcut issue, so it is now aimed at both the Search and Hide Toolbar features. It's great that there are new features in the pipeline for future versions of Admin Toolbar!
Thanks @sascha_meissner for sharing your idea and code, and @grevil and @thomas.frobieter for pushing this feature forward! It's very encouraging with the friendly and positive approach from for example DROWL.de developers and @dydave, where the tone can occasionally be a bit too focused on efficiency in some issues, with hardly a thank you or gratitude. So I really appreciate the positive tone in the many projects you are maintaining, and issues you are involved in.
Comment #81
sascha_meissnerWow i´ve been off for 2 months family time and did not expect THIS to happen 😍
Thank you so much for following up on this @ressa @grevil @dydave @thomas.frobieter and everybody else on this