Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app/assets/tailwind/layered_ui/engine.css
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,16 @@
mask-size: contain;
}

/* transition-none is intentional: the after-change style determines the
transition, so this gives "animate open, snap shut" - opening matches the
base rule (animates), closing matches this rule (snaps instantly). */
.l-ui-navigation__section-toggle[aria-expanded="false"] .l-ui-navigation__section-chevron {
@apply -rotate-90;
@apply -rotate-90
transition-none;
}

.l-ui-navigation__section-toggle--no-transition .l-ui-navigation__section-chevron {
@apply transition-none;
}

.l-ui-navigation__section-items {
Expand All @@ -771,6 +779,22 @@
gap-0.5 px-3 py-3;
}

@keyframes l-ui-navigation-slide-down {
from {
opacity: 0;
transform: translateY(-0.375rem);
}

to {
opacity: 1;
transform: translateY(0);
}
}

.l-ui-navigation__section-items--opening > li {
animation: l-ui-navigation-slide-down 0.2s ease-out both;
}

.l-ui-navigation__user {
@apply shrink-0
p-4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,29 @@ export default class extends Controller {
if (stored === null) return

const isOpen = stored === "true"
this.toggleTarget.setAttribute("aria-expanded", isOpen ? "true" : "false")
// Apply the restored state without animating the chevron on load; it should
// simply render in the correct position.
const toggle = this.toggleTarget
toggle.classList.add("l-ui-navigation__section-toggle--no-transition")
toggle.setAttribute("aria-expanded", isOpen ? "true" : "false")
if (isOpen) {
this.panelTarget.removeAttribute("hidden")
} else {
this.panelTarget.setAttribute("hidden", "")
}
requestAnimationFrame(() => {
requestAnimationFrame(() => {
toggle.classList.remove("l-ui-navigation__section-toggle--no-transition")
})
})
}

toggle() {
const isOpen = this.toggleTarget.getAttribute("aria-expanded") !== "true"
this.toggleTarget.setAttribute("aria-expanded", isOpen ? "true" : "false")
if (isOpen) {
this.panelTarget.removeAttribute("hidden")
this.#animateOpen()
} else {
this.panelTarget.setAttribute("hidden", "")
}
Expand All @@ -45,4 +55,14 @@ export default class extends Controller {
// ignore
}
}

// Slide the items in only on user-initiated open, not on initial page load.
#animateOpen() {
const panel = this.panelTarget
const CLASS = "l-ui-navigation__section-items--opening"
panel.classList.add(CLASS)
panel.addEventListener("animationend", () => {
panel.classList.remove(CLASS)
}, { once: true })
}
}
Loading