Skip to content

Commit

Permalink
Move view transition inside history buttons so it doesn't affect key …
Browse files Browse the repository at this point in the history
…presses
  • Loading branch information
Inwerpsel committed Dec 27, 2024
1 parent 8b02157 commit c97ce9a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 54 deletions.
74 changes: 37 additions & 37 deletions docs/demo/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/demo/dist/bundle.js.map

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/components/ui/HistoryControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ function HistoryBack() {
className={'history-button'}
disabled={noHistory}
title={noHistory ? 'No history' : remainingLength}
onClick={historyBackOne}
// This and the next view transition are added here because it's a relatively safe place to showcase it,
// while not being too affected by its major drawbacks.
// Still, it causes the button to become unresponsive to clicks during the transition,
// and even results in a text selection being made of the component that it would otherwise never do when
// clicking on a button element.
// All of this happens even if the button does not move during the transition.
// So this uses a view transition mostly because it's a very clear demonstration of these drawbacks,
// and the other history UI makes it so you don't realy need these buttons anyway.
onClick={() => doTransition(() => historyBackOne())}
>
</button>;
}
Expand All @@ -42,7 +50,7 @@ function HistoryForward() {
className={'history-button'}
disabled={noFuture}
title={noFuture ? 'No future' : historyOffset}
onClick={historyForwardOne}
onClick={() => doTransition(() => historyForwardOne())}
>
</button>;
}
Expand Down
16 changes: 2 additions & 14 deletions src/hooks/useResumableReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,11 @@ function isFullyPinned(entry: HistoryEntry) {
}

export function historyBackOne(): void {
// This and the next view transition are added here because it's a relatively safe place to showcase it,
// while not being too affected by its major drawbacks.
// Still, it causes the button to become unresponsive to clicks during the transition,
// and even results in a text selection being made of the component that it would otherwise never do when
// clicking on a button element.
// All of this happens even if the button does not move during the transition.
// So this uses a view transition mostly because it's a very clear demonstration of these drawbacks,
// and the other history UI makes it so you don't realy need these buttons anyway.
doTransition(() => {
historyBack(1);
});
historyBack(1);
}

export function historyForwardOne(): void {
doTransition(() => {
historyForward(1);
});
historyForward(1);
}

export function historyBackFast(): void {
Expand Down

0 comments on commit c97ce9a

Please sign in to comment.