diff --git a/inst/components/scss/sidebar.scss b/inst/components/scss/sidebar.scss index be3318ac1..652c7828e 100644 --- a/inst/components/scss/sidebar.scss +++ b/inst/components/scss/sidebar.scss @@ -133,8 +133,6 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--bslib-sidebar-icon-size)), > .collapse-toggle { grid-row: 1 / 2; grid-column: 1 / 2; - display: inline-flex; - align-items: center; position: absolute; right: calc(var(--bslib-sidebar-icon-size)); top: calc(var(--bslib-sidebar-icon-size, 1rem) / 2); @@ -147,29 +145,26 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--bslib-sidebar-icon-size)), justify-content: center; padding: 0; color: var(--bslib-sidebar-fg); - background-color: unset; // don't take `button` background color + transform: rotateY(var(--bslib-collapse-toggle-transform)); transition: - color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), - top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), + // N.B. In order to properly add/remove the .transitioning class (in JS), + // we assume on this `right` property will fire a transitionend event right var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), - left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration); + top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), + left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), + color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration), + transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration); + opacity: 0.8; + background-color: unset; // don't take `button` background color &:hover { + opacity: 1; background-color: var(--bslib-sidebar-toggle-bg); } - > * { - opacity: 0.8; + > * { width: var(--bslib-sidebar-icon-size); height: var(--bslib-sidebar-icon-size); - transform: rotateY(var(--bslib-collapse-toggle-transform)); - // N.B. since mobile view won't trigger a transition of grid-template-columns, - // we transition this toggle to ensure _some_ transition event always happens. - transition: transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration); - } - - &:hover > * { - opacity: 1; } } diff --git a/srcts/src/components/sidebar.ts b/srcts/src/components/sidebar.ts index 5f59a7def..b1b41a1bf 100644 --- a/srcts/src/components/sidebar.ts +++ b/srcts/src/components/sidebar.ts @@ -228,13 +228,14 @@ class Sidebar { this.toggle("toggle"); }); - // Remove the transitioning class when the transition ends. We watch the - // collapse toggle icon because it's guaranteed to transition, whereas the - // sidebar doesn't animate on mobile (or in browsers where animating - // grid-template-columns is not supported). - toggle.firstElementChild?.addEventListener("transitionend", () => - this._finalizeState() - ); + // When the toggle's done transitioning, finalize the sidebar state + // (e.g., remove the transitioning class). + // N.B. assumes the toggle's right property is transitioned... + toggle.addEventListener("transitionend", (e) => { + if (e.target !== toggle) return; + if (e.propertyName !== "right") return; + this._finalizeState(); + }); } /**