I've been playing around with making the sidebar sticky with position: sticky. It works pretty well, and is not a lot of code.
Would love to have people's thoughts.
We could make this a theme-setting, too.

| Comment | File | Size | Author |
|---|---|---|---|
| #24 | Sticky sidebar.gif | 5.23 MB | jazzper |
| #22 | thepatch.png | 94.9 KB | ressa |
| #20 | olivero-sticky-9.4.gif | 1.47 MB | ressa |
| #5 | 3174774-5.patch | 4.41 KB | mherchel |
| #2 | 3174774.patch | 2.37 KB | mherchel |
Issue fork drupal-3174774
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
mherchelComment #3
ressaHaving a sticky block sometimes makes sense, so I think that would be great to have as an option. But like you write, probably optional and configurable via a theme-setting. Can it be per block, or would it have to be on-or-off for all blocks?
Comment #4
mherchelIt would be a global setting. Thanks for the feedback!
Comment #5
mherchelNewest patch contains a setting (enabled by default) to enable/disable the sticky.
Comment #6
ressaIt looks great, and works just as expected, thanks!
Comment #8
mherchelThanks! Yeah, I like it. Committing :)
Comment #10
mherchelReverting commit and re-opening. According to @Gábor Hojtsy in Slack, we don't want any new "features" in the core patch (which would necessitate new reviews).
Comment #11
mherchelComment #12
mherchelComment #13
andrewmacpherson commentedA problem with
position: stickyis it doesn't take the amount of sidebar content into account.Consider this situation:
In this case, you have to scroll to the end of a very long page, to see the end of the short sidebar. Without the sticky positioning, you'll only have to scroll a short distance to see the end of the sidebar.
The GIF in the issue summary doesn't show the problem, because the sidebar content is slightly shorter than the viewport. Try making the browser window height about 100px shorter to see the problem (or add a couple more sentences in the sidebar content).
Making it a configurable theme setting mitigates the problem somewhat, but it then permissions get in the way. The approach falls down where a content editor has permission to manage blocks (or layout builder?) but doesn't have permission to change theme setting. A site builder can't anticipate how much content a content manager will put in the sidebar.
Comment #14
andrewmacpherson commentedThere's a potential accessibility issue with using
position: stickyon a sidebar. Watch the demo GIF in the issue summary carefully...Scott O' Hara suspects that "such behaviour could be considered a form of parallax scrolling". So he avoids using the sticky position when the
prefers-reduced-motionmedia feature is in play. I think this is an interesting situation, and I think it's worth putting this in for safety. The theme settings form could briefly mention this in a#description, in case any site builders think it isn't working.Comment #15
mherchelComment #18
jazzper commentedHi!
First of all thanks for all the work!
This is exactly what I want and I would like to help test it. I want to use this for social links which I want to stay visible while scrolling down. The patch is not applying to my codebase with composer (I use "cweagans/composer-patches": "^1.6"). I use drupal/core and not drupal/recommended-project (don't know if this is relevant). My drupal codebase is in a web folder. My composer.json one level higher.
It seems that composer can't find the files (because its not looking in the olivero theme dir). This is the output of the first bit:
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-10-05/3174774-5.patchI guess I do something wrong. I googled but could not find anything that helps me solve this.
I also tried to replace
drupal/corewithdrupal/oliverobut then composer tells me there is nothing to install, update or remove.In the meantime, I use CSS which also works pretty well (I just add this in case somebody looking for a solution reads this).
Comment #20
ressaI agree @jazzper, @mherchel's suggestion about adding a sidebar "sticky" option is great, and his patch works perfectly, so I also hope it can get implemented in Drupal core at some point.
The original patch has to be applied from inside the theme folder, so for it to work with Composer I have re-rolled the patch for Drupal 9.4 via the newish Gitlab integration. To try the patch, use one of these options:
PS. The test fails, I don't know why, but the feature works, as can be seen here:
Comment #21
jazzper commentedHi @ressa,
Thanks for your response! Maybe I'm missing something or maybe it's because the test doesn't pass but I don't see a re-rolled patch.
I thought the sticky sidebar was for the social bar on the left. But now I see it's the right sidebar. Still, a nice feature and I would like to have it on my website and help with testing.
Comment #22
ressaIt's because in the new Gitlab integration, patches are at the top, together with link to the issue fork, the branch, Merge Request, etc. :)
Comment #23
ressaAnd you're right, nice catch: With this patch only the right hand side block is stickied, so it needs work if also the social bar on the left should stick :)
Comment #24
jazzper commentedThanks for the explanation!
I applied the patch and it's working great! I use it for a Table of content views block showing all the h2's of my paragraphs. I configured them as anchor links so that people can go to the relevant section of my content by clicking them.
One thing that could be improved IMHO is a way for the main menu not to overlap with the block when the menu is expanded. Or maybe that by navigating to another page the menu doesn't stay expanded. Of course, a user can close the menu by clicking on the X but not every user might realize this.
Anyway, it's working really well!
Comment #26
idflorin commented@mherchel
Thanks! I was looking for something like that for my EVS subtheme of Olivero
I adapted the patch to my EVS subtheme of Olivero
Step 1. add
to evs.theme
Step 2. add
to style.css
You can see it at EV stories.
Comment #28
mgiffordTagging for