Repository navigation
fix(page_sidebar): Improve page sidebar and mobile flow behavior - #908
Merged
Merged
Conversation
gadenbuie
marked this pull request as ready for review
November 16, 2023 15:29
gadenbuie
force-pushed
the
fix/page-sidebar-height-mobile
branch
from
November 16, 2023 15:31
f066374 to
d737f0e
Compare
gadenbuie
commented
Nov 16, 2023
cpsievert
reviewed
Nov 16, 2023
| grid-column: 1 / 2; | ||
| width: 100%; | ||
| height: 100%; | ||
| border-right: var(--_vert-border); |
Collaborator
There was a problem hiding this comment.
I think we should bring back the width: 100%
Member
Author
There was a problem hiding this comment.
I checked all of our rules and .sidebar always has both grid-column and grid-row properties, which drive the height and width of the sidebar container. I'm comfortable with both being redundant, but happy to leave width for now if you want.
gadenbuie
commented
Nov 16, 2023
| $bslib-sidebar-toggle-bg: rgba(var(--bs-emphasis-color-rgb, 0,0,0), 0.1) !default; | ||
| $bslib-sidebar-border: var(--bs-card-border-width, #{$card-border-width}) solid var(--bs-card-border-color, #{$card-border-color}) !default; | ||
| $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_icon-size)), var(--_sidebar-width)); | ||
| $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_padding-icon)), var(--_sidebar-width)); |
Member
Author
There was a problem hiding this comment.
In desktop mode, if the sidebar is too wide for the container, this ensures that the sidebar doesn't expand too far, leaving one collapse icon's worth of space in the main area. Which is useful if there are nested sidebars. (Slightly tangential to this PR but I didn't want to forget to fix this.)
cpsievert
reviewed
Nov 16, 2023
cpsievert
reviewed
Nov 16, 2023
cpsievert
approved these changes
Nov 16, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue with the height of the sidebar on mobile and improves the mobile flow behavior.
Problem: Sidebar height on mobile
The interaction between the
height: autoon the.bslib-page-fillcontainer (applied to mobile-sized screens) and theheight: 100%on the.sidebarcontainer of thepage_sidebar()layout caused unexpected behavior in both Safari and Chrome/Firefox.In Safari, the sidebar would be the full height of the screen, but the children of the main container would resize depending on the state of the sidebar. In the video below, you can see that when the sidebar is expanded, it's
height: 100%causes the sidebar layout container to resize to 100% of the viewport, causing the children of the main content area to resize as well. When the sidebar is collapsed and theheight: 100%is removed, the elements return to their expected sizes. This causes jumpy plots around the transition.Kapture.2023-11-16.at.09.51.18.mp4
This behavior results from Safari's unique interpretation of the behavior of a
height: 100%element when its parent hasheight: auto.Unfortunately, in Chrome and Firefox, we don't get the results we're expecting either. In the video below, in Firefox on mobile, you can see that the layout container uses the intrinsic height of the main contents, which are shorter than the full viewport height, and therefore the sidebar is shorter than expected.
Kapture.2023-11-16.at.09.52.33.mp4
Fix: Full height sidebar and mobile flow
The primary fix involves avoiding two things:
height: 100%on the.sidebarcontainer.height: autoinpage_fillable()to toggle filling behaviorThe
height: 100%on the sidebar container is unnecessary. I think we may have needed it in a previous iteration and kept it out of caution.The use of
height: autoin page fillable is subtle, but probably not what we wanted for a more than just the behavior described above for a couple of reasons:page_fillable()disables fillability on the outer container, but in the context of a sidebar we want to keep fillable behavior at the outer edge and instead disable fillability of the main content area of the sidebar layout.height: auto, I considered of togglingdisplay: blockordisplay: flexbut this presents another problem. If we move from a flex container to a block container, all of thebslib-gap-spacingclasses will still be present and we'll lose the vertical spacing between elements.In short, we need to toggle fill behavior while retaining
display: flexand we'll need more than a single CSS property to control behavior.In this PR, I added
.bslib-flow-mobile, which generally speaking is a class that can be used anywhere to disable the fill behavior of its immediate children. This class is now applied topage_fillable(fillable_mobile = FALSE). (Technically, it setsflex: none;on.html-fill-itemdirect children.)Then,
.bslib-page-sidebarreceived an exception to instead break fillability on the children of the page's sidebar main content area. Because the main content area can now scroll inside the page, we also need to adjust the collapse toggle position of that outer sidebar.Safari
After these changes, on Safari, the sidebar no longer causes the plot size to jump during transition.
Kapture.2023-11-16.at.09.53.44.mp4
Chrome/Firefox
On Chrome/Firefox, the sidebar is now full height, even if the elements inside are scrolling.
Kapture.2023-11-16.at.09.53.09.mp4
Collapse toggle position
Kapture.2023-11-16.at.09.54.34.mp4
Preview on real mobile
Here's a short preview on a real mobile phone (iPhone 13), with both
fillable_mobile = FALSEandfillable_mobile = TRUE.RPReplay_Final1700148539.MP4
Flow utility classes
I think
.bslib-flow-mobileis going to be generally useful, but I also see utility in having additional utility classes that can opt into flow behavior at various breakpoints. I added.bslib-flow-sm,.bslib-flow-mdand.bslib-flow-lgthat turn on flow behavior at or below the breakpoint suffix – i.e..bslib-flow-mddisables fillability for medium-sized screens below themdbreakpoint.