Skip to content

Commit cf72028

Browse files
committed
Apply more styles/logic to toggle icon's container (not the icon itself)
1 parent 31cf806 commit cf72028

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

inst/components/scss/sidebar.scss

+11-16
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--bslib-sidebar-icon-size)),
133133
> .collapse-toggle {
134134
grid-row: 1 / 2;
135135
grid-column: 1 / 2;
136-
display: inline-flex;
137-
align-items: center;
138136
position: absolute;
139137
right: calc(var(--bslib-sidebar-icon-size));
140138
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)),
147145
justify-content: center;
148146
padding: 0;
149147
color: var(--bslib-sidebar-fg);
150-
background-color: unset; // don't take `button` background color
148+
transform: rotateY(var(--bslib-collapse-toggle-transform));
151149
transition:
152-
color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
153-
top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
150+
// N.B. In order to properly add/remove the .transitioning class (in JS),
151+
// we assume on this `right` property will fire a transitionend event
154152
right var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
155-
left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration);
153+
top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
154+
left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
155+
color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
156+
transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration);
156157

158+
opacity: 0.8;
159+
background-color: unset; // don't take `button` background color
157160
&:hover {
161+
opacity: 1;
158162
background-color: var(--bslib-sidebar-toggle-bg);
159163
}
160164

161-
> * {
162-
opacity: 0.8;
165+
> * {
163166
width: var(--bslib-sidebar-icon-size);
164167
height: var(--bslib-sidebar-icon-size);
165-
transform: rotateY(var(--bslib-collapse-toggle-transform));
166-
// N.B. since mobile view won't trigger a transition of grid-template-columns,
167-
// we transition this toggle to ensure _some_ transition event always happens.
168-
transition: transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration);
169-
}
170-
171-
&:hover > * {
172-
opacity: 1;
173168
}
174169
}
175170

srcts/src/components/sidebar.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,14 @@ class Sidebar {
228228
this.toggle("toggle");
229229
});
230230

231-
// Remove the transitioning class when the transition ends. We watch the
232-
// collapse toggle icon because it's guaranteed to transition, whereas the
233-
// sidebar doesn't animate on mobile (or in browsers where animating
234-
// grid-template-columns is not supported).
235-
toggle.firstElementChild?.addEventListener("transitionend", () =>
236-
this._finalizeState()
237-
);
231+
// When the toggle's done transitioning, finalize the sidebar state
232+
// (e.g., remove the transitioning class).
233+
// N.B. assumes the toggle's right property is transitioned...
234+
toggle.addEventListener("transitionend", (e) => {
235+
if (e.target !== toggle) return;
236+
if (e.propertyName !== "right") return;
237+
this._finalizeState();
238+
});
238239
}
239240

240241
/**

0 commit comments

Comments
 (0)