1
0
Fork 0

feat(npc-dialogue): slide the choice menu in instead of knocking the text up

The footer used to appear in one frame, so the fixed frame's log lost its height
at once and every line above jumped upward as the player was reading it. The
footer is now a grid row that grows from 0fr to 1fr over 300ms, with the log
giving up height in step, and the buttons stagger in behind it at 40ms each.
A ResizeObserver keeps the log pinned to the bottom while that happens, but only
when the player is already near the bottom.

Measured: 19 frames from 0 to 163px, log 529 to 366 in lockstep, dialog box
unchanged at 162px/576px. Under prefers-reduced-motion the computed
transition-property is none, so the menu lands at once.

The exit stays instant: a pick swaps the menu for the player's typing indicator.
This commit is contained in:
Jason Fraley 2026-11-24 19:42:17 -05:00
parent cde1e2f5d1
commit ccbbeaaa99
2 changed files with 65 additions and 12 deletions

View file

@ -549,6 +549,16 @@ export function NpcConversation({
: [];
const anySelectableChoice = visibleChoices.some((choice) => !choice.locked);
/** The node whose options belong on screen. Null while anything is still
* arriving, which is what opens and closes the footer: the row animates from
* 0fr to 1fr, so the menu slides in instead of the text jumping. */
const footerNode = (() => {
if (typing !== null || playerTyping || streamingId !== null) return null;
if (!lastNode || lastNode.kind !== "node") return null;
const node = lastNode.node;
return node.type === "choice" || node.type === "end" ? node : null;
})();
// Keep the newest line in view. `streamingId` and the choice count are in the
// dependencies because the footer appearing (or a menu growing) changes how
// much room the log has, and the log would otherwise leave the newest line
@ -558,6 +568,21 @@ export function NpcConversation({
if (el) el.scrollTop = el.scrollHeight;
}, [log, typing, playerTyping, open, streamingId, visibleChoices.length]);
// The footer grows over several frames, so the log keeps shrinking after the
// effect above has run. Follow it while the player is at the bottom; if they
// scrolled up to re-read something, leave their position alone.
useEffect(() => {
const el = scrollRef.current;
if (!el || typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(() => {
if (el.scrollHeight - el.clientHeight - el.scrollTop < 40) {
el.scrollTop = el.scrollHeight;
}
});
observer.observe(el);
return () => observer.disconnect();
}, []);
/** Button text for a choice: the server-resolved label when the choice
* node's strings contained flag tokens, the raw label otherwise. */
@ -676,6 +701,7 @@ export function NpcConversation({
if (streamingId) skipRevealRef.current = streamingId;
else skipBeatRef.current = true;
}}
data-log="conversation"
className="min-h-0 flex-1 overflow-y-auto p-5"
>
{/* Bottom-anchored like a messenger: a short conversation sits
@ -715,14 +741,21 @@ export function NpcConversation({
</div>
</div>
{!typing &&
!playerTyping &&
streamingId === null &&
lastNode &&
lastNode.kind === "node" &&
(lastNode.node.type === "choice" || lastNode.node.type === "end") && (
<div className="flex max-h-[45%] shrink-0 flex-col gap-2 overflow-y-auto border-t border-white/15 bg-black/50 p-4">
{lastNode.node.type === "choice" && visibleChoices.length > 0 && (
{/* The footer opens by growing its grid row, so the menu slides in
and the log above it gives up height over the same 260ms
instead of the text jumping up in one frame. Always mounted so
the transition has something to animate; `motion-reduce`
collapses the timing to nothing. */}
<div
data-footer="choices"
className={`grid shrink-0 overflow-hidden transition-[grid-template-rows] duration-300 ease-out motion-reduce:transition-none ${
footerNode ? "grid-rows-[1fr]" : "grid-rows-[0fr]"
}`}
>
<div className="min-h-0">
{footerNode && (
<div className="flex max-h-[260px] flex-col gap-2 overflow-y-auto border-t border-white/15 bg-black/50 p-4">
{footerNode.type === "choice" && visibleChoices.length > 0 && (
<TooltipProvider delayDuration={150}>
{visibleChoices.map(({ hop, index, locked }) => {
const isNew = unseenTargets.has(hop.target);
@ -731,7 +764,8 @@ export function NpcConversation({
type="button"
disabled={locked}
onClick={() => pick(hop, index, choiceLabel(hop, index))}
className={`w-full rounded-none border px-3 py-2 text-left text-sm transition-colors ${
style={{ animationDelay: `${Math.min(index, 6) * 40}ms` }}
className={`w-full rounded-none border px-3 py-2 text-left text-sm transition-colors animate-in fade-in-0 slide-in-from-bottom-1 fill-mode-both duration-200 motion-reduce:animate-none ${
locked
? "cursor-not-allowed border-white/10 bg-black/20 text-white/35"
: "border-white/20 bg-black/40 text-white/80 hover:border-cyan-500/60 hover:text-white"
@ -767,7 +801,7 @@ export function NpcConversation({
})}
</TooltipProvider>
)}
{(lastNode.node.type === "end" || !anySelectableChoice) && (
{(footerNode.type === "end" || !anySelectableChoice) && (
<Button
onClick={close}
className="w-full rounded-none border border-white/20 bg-black/40 text-xs uppercase tracking-widest text-white/80 hover:border-cyan-500/60 hover:bg-black/40 hover:text-white"
@ -776,7 +810,9 @@ export function NpcConversation({
</Button>
)}
</div>
)}
)}
</div>
</div>
</>
)}
</DialogContent>

View file

@ -243,7 +243,24 @@ it, `justify-end` puts overflow above the scroll origin where it cannot be reach
The auto-scroll effect depends on `streamingId` and `visibleChoices.length` as well
as the log: the footer appearing (or a menu gaining items) changes how much room the
log has, and without those the newest line can end up scrolled out of sight.
log has, and without those the newest line can end up scrolled out of sight. A
`ResizeObserver` on the log keeps pinning it to the bottom while the footer animates,
but only when the player is already near the bottom, so nobody reading further up
gets yanked.
**The footer slides in.** It is wrapped in a grid whose
`grid-template-rows` goes `0fr` to `1fr` over 300ms, with the item `min-h-0` and the
wrapper `overflow-hidden`; the content mounts at the same moment the row starts
growing, so the log gives up height progressively and the lines above glide instead
of being knocked upward in one frame (measured: 19 frames from 0 to 163 px, log 529
to 366 in step). The buttons stagger in behind it with `animate-in` and a 40ms
per-item delay. `motion-reduce` sets `transition-property: none`, so the menu lands
at once for a reduced-motion device.
The **exit is deliberately instant**: a pick swaps the footer for the player's typing
indicator, and the menu vanishing the moment it is used is the expected feedback.
Animating it out would mean latching the last choice node so its buttons could stay
mounted while collapsing; that is not worth the extra state unless someone asks.
## AI drafting behaviour worth knowing