-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sidebar): Independently customize sidebar state on mobile and desktop screens #943
Merged
Conversation
This file contains 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
cpsievert
reviewed
Dec 18, 2023
cpsievert
reviewed
Dec 18, 2023
cpsievert
reviewed
Dec 18, 2023
cpsievert
reviewed
Dec 18, 2023
cpsievert
reviewed
Dec 18, 2023
cpsievert
reviewed
Dec 18, 2023
gadenbuie
force-pushed
the
feat/sidebar-open-mobile-desktop
branch
from
December 18, 2023 20:47
048bed4
to
18372a7
Compare
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
reviewed
Dec 19, 2023
cpsievert
approved these changes
Dec 19, 2023
Co-authored-by: Carson Sievert <[email protected]>
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.
Fixes #941
Custom screen-size initial state options
This PR allows users to choose the initial sidebar state for desktop and mobile devices. For example, the current
open = "desktop"
default is equivalent toYou could achieve an always-open sidebar on mobile devices, with a collapsible sidebar on desktop devices with
If, as in the above case, the sidebar is always open in one size but collapsible in another, we need watch the window size and manually set the sidebar state if we move from a collapsible size to an always open size. Imagine a user collapsed the sidebar on a desktop-sized screen and then resizes the window to a mobile size (where we need to open the sidebar, in addition to ensuring that its visible).
Because of this, we also now better handle moving between small and large sizes when the sidebar is not collapsible at one of the two sizes. In the above case, when moving from mobile to desktop, we'll ensure the sidebar remains open, but if
and the user moves from mobile to desktop, we'll follow the initial state and have the sidebar be closed when they cross into desktop sizes.
Side note: If the sidebar is always collapsible, we don't add the window resize event listener to avoid unnecessary event handlers. We also don't watch or update the collapsible/initial state attributes, although we do re-consult them. With a bit more time we could refactor the sidebar layout into a custom element or web component, in which case it'd make a lot of sense to make those attributes reactive.
Public API
In an early iteration of this PR, we added
sidebar_open_on()
to the public API. We are choosing not to export this function at this time, but we've kept it in the codebase and could easily export it in the future.Page-level sidebars
In addition to the above changes, we also updated
sidebar(open = NULL)
as the new default value. This allows parent containers to take a sidebar argument and supply their ownopen
default if not otherwise provided by the user. We use this inpage_sidebar()
andpage_navbar()
to make page-level sidebars useopen = list(desktop = "open", mobile = "always")
by default.This motivated some internal refactoring to have
sidebar()
return the sidebar data itself but delay rendering to tags. I added a new S3 method foras.tags()
for the classbslib_sidebar
that is called bylayout_sidebar()
to render the collapse and sidebar tags using the data structure returned bysidebar()
(and that may have even been modified between callingsidebar()
and handing the data off tolayout_sidebar()
).Just as I'd like to refactor the Typescript to use web components, I'd like to refactor
sidebar()
andlayout_sidebar()
to use R6 -- in the interest of delivering this new feature quickly I've done neither of those things 😇Example App
Kapture.2023-12-14.at.17.08.02.mp4
App Code