Skip to content

Commit

Permalink
fix back navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Sep 25, 2024
1 parent 83e2556 commit 60db4dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-seas-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vtbag/turn-signal': patch
---

Fixes a bug where backward animations didn't work as advertised
20 changes: 5 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function pageReveal(e: PageRevealEvent) {
const pages = allPages();
let hereIdx = 1,
fromIdx = 0;
if (act.navigationType === 'traverse' && !allPages) {
if (act.navigationType === 'traverse' && pages.length === 0) {
hereIdx = act.entry?.index;
fromIdx = act.from?.index;
} else {
Expand Down Expand Up @@ -37,11 +37,7 @@ function pageReveal(e: PageRevealEvent) {
}
const attributeName = direction.shift()!;
value =
hereIdx < fromIdx
? direction[0]
: hereIdx === fromIdx
? direction[1]
: direction[2];
hereIdx < fromIdx ? direction[0] : hereIdx === fromIdx ? direction[1] : direction[2];
if (attributeName && value) {
document.documentElement.setAttribute(attributeName, value);
e.viewTransition.finished.then(() =>
Expand All @@ -52,7 +48,6 @@ function pageReveal(e: PageRevealEvent) {
direction = ['backward', 'same', 'forward'];
dir = currentScript!.dataset.directionTypes;
if (dir) {

direction = dir.trim().split(/\s*,\s*/);

if (direction.length !== 3) {
Expand All @@ -62,12 +57,7 @@ function pageReveal(e: PageRevealEvent) {
return;
}
}
value =
hereIdx < fromIdx
? direction[0]
: hereIdx === fromIdx
? direction[1]
: direction[2];
value = hereIdx < fromIdx ? direction[0] : hereIdx === fromIdx ? direction[1] : direction[2];
if (value) e.viewTransition.types.add(value);
}
}
Expand All @@ -77,8 +67,8 @@ function allPages() {
const selector = currentScript!.dataset.selector;
return selector
? [...document.querySelectorAll<HTMLAnchorElement>(selector)].map(
(e) => new URL(e.href ?? '.', location.href).pathname
)
(e) => new URL(e.href ?? '.', location.href).pathname
)
: [];
}

Expand Down

0 comments on commit 60db4dd

Please sign in to comment.