Skip to content

feat(sidebar): Mobile default improvements - #907

Merged
gadenbuie merged 16 commits into
mainfrom
sidebar/fix-init
Nov 16, 2023
Merged

gadenbuie merged 16 commits into
mainfrom
sidebar/fix-init

Conversation

@gadenbuie

@gadenbuie gadenbuie commented Nov 15, 2023 •

Copy link
Copy Markdown
Member

The biggest change in this PR is to avoid a CSS animation for sidebars with open="desktop" when initializing the sidebar on mobile screen sizes. With this default, layout_sidebar() provides initially correct markup for open sidebars, but we close the sidebar when initialized. Previously, we would use the exact same code path as if the user had clicked the collapse toggle, but this caused a distracting animation on page load.

We now instead skip the transition – mostly use the same code path – but without adding the .transitioning class. In this way, the sidebar closes immediately but we don't lose the aria labels and other appropriate accessibility markup that we require. Here's a sketch of those changes:

  1. When open="desktop", on small screens, we now add the collapsed class, without including the .transitioning class and immediately invoke _finalizeState().
  2. All CSS animations in the sidebar now only apply when the .transitioning class is added before the state-changing class is toggled. This is achieved by enabling --_transition-duration only when the .transitioning class is added.
  3. I did break the contract that we emit "initially correct markup for open sidebars" by adding hidden to the open="desktop" sidebar element. We remove this attribute if the sidebar should be open. This prevents some layout jumps from happening if the sidebar's contents are briefly shown before being closed.

While in this area, I also:

  • Added --bslib-sidedbar-mobile-max-width, --bslib-sidebar-mobile-opacity and --bslib-sidebar-mobile-box-shadow CSS custom properties that be set globally (or --_sidebar-mobile-* for locally scoped changes). We don't use these yet, but they open the door for working with design variations of the sidebar on mobile.

  • I adjusted the sidebar transition duration default from 500ms to 300ms for a snappier transition.

@gadenbuie gadenbuie self-assigned this Nov 15, 2023
@gadenbuie
gadenbuie requested a review from cpsievert November 15, 2023 22:41
Comment thread srcts/src/components/sidebar.ts Resolved
Comment thread inst/components/scss/sidebar.scss Resolved
Comment thread inst/components/scss/sidebar.scss Resolved
Comment thread inst/components/scss/sidebar.scss Resolved
Comment thread inst/components/scss/sidebar.scss Resolved
@gadenbuie
gadenbuie requested a review from cpsievert November 16, 2023 21:35
Comment thread inst/components/scss/sidebar.scss Resolved
@gadenbuie
gadenbuie merged commit fde2d16 into main Nov 16, 2023
@gadenbuie
gadenbuie deleted the sidebar/fix-init branch November 16, 2023 23:48
cpsievert added a commit to posit-dev/py-shiny that referenced this pull request Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants