Teleport every modal to <body>, fixing an unclickable-behind-page bug

Reported from the sidebar's own per-document delete: the confirm modal
appeared behind the main content and couldn't be clicked.

Root cause: .app-sidebar (position:sticky) and .txn-col
(container-type:inline-size, which implies layout containment) each
always create their own CSS stacking context, with or without an
explicit z-index. ConfirmModal/DocumentOptionsModal/DownloadChoiceModal
are rendered as DOM descendants of one or the other depending on which
call site opens them, so their own z-index:50 was trapped inside that
ancestor's local stacking order - no z-index value could escape it,
since z-index only ever competes against siblings within the same
stacking context.

Fixed with <Teleport to="body"> on all three modals - the standard fix
for this bug, not a bigger z-index (which cannot escape a trapped
stacking context regardless of the number). Each modal now always
renders as a direct child of <body>, a sibling of #app rather than a
descendant of whichever component opened it, so this can't recur
regardless of which future component ends up opening one.

Verified: npm run build passes, the bundle references Teleport, the app
container rebuilt. measure.py unaffected. Not machine-verified -
Claude-in-Chrome did not connect this session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
JasonFraser 2026-10-13 13:36:32 -04:00
parent 42ff3e364f
commit 23bba7e760
4 changed files with 135 additions and 77 deletions

View File

@ -1450,6 +1450,32 @@ separate computed with no dependency on `SourceDocumentPanel`'s state at all. Fi
confirmed bug; **did not claim the transactions-table symptom is resolved** - asked the confirmed bug; **did not claim the transactions-table symptom is resolved** - asked the
user to retest specifically that, since no code path was found connecting the two. user to retest specifically that, since no code path was found connecting the two.
**All three modal components teleported to `<body>`, fixing a real "modal appears behind
the page, unclickable" bug reported from the sidebar's own per-document delete.** Root
cause: `.app-sidebar` (`position:sticky`) and `.txn-col` (`container-type:inline-size`,
which implies layout containment) each create their own CSS stacking context - ALWAYS,
with or without an explicit z-index. `ConfirmModal`/`DocumentOptionsModal`/
`DownloadChoiceModal` are all rendered as DOM descendants of one or the other depending
on which call site opened them, so their own `.modal-overlay`'s `z-index:50` was
**trapped inside that ancestor's local stacking order** - no z-index value could have
fixed this, since z-index is only ever compared against siblings within the SAME
stacking context; `.app-sidebar`/`.txn-col` themselves have no elevated z-index of their
own, so their entire subtree (modal included) could be painted under later, unrelated
page content regardless of what number the modal's own z-index carried.
Fixed with `<Teleport to="body">` wrapping each modal's root element - the standard Vue
fix for this exact class of bug, not a bigger z-index (which cannot escape a stacking-
context trap no matter the value chosen). All three modals now always render as a
direct child of `<body>`, a SIBLING of `#app` rather than a descendant of whichever
component happened to open them, so they're never trapped inside any ancestor's
stacking context again, regardless of which future component ends up opening one.
Verified: `npm run build` passes; the built bundle confirmed to reference `Teleport`;
the `app` container rebuilt. `measure.py` unaffected (no backend touched). Not
machine-verified: whether the modal now actually appears above everything and is
clickable from every call site (sidebar delete, document delete, move-to-project,
download choice) - Claude-in-Chrome still did not connect this session.
**Governing rule: never silently correct or exclude data.** This shows up in several **Governing rule: never silently correct or exclude data.** This shows up in several
concrete places, not just as an abstract principle: concrete places, not just as an abstract principle:
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is - A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is

View File

@ -5,8 +5,22 @@
* A small, generic confirm/cancel modal - originally built for * A small, generic confirm/cancel modal - originally built for
* TransactionsTable's "Move to project" dropdown, now also reused for * TransactionsTable's "Move to project" dropdown, now also reused for
* destructive document deletion (see DocumentNavBar.vue's "Delete this * destructive document deletion (see DocumentNavBar.vue's "Delete this
* document" flow) - `danger` swaps the confirm button to the red/danger * document" flow, and ProjectSidebar.vue's own per-document delete) -
* treatment for that case. * `danger` swaps the confirm button to the red/danger treatment for
* that case.
*
* Rendered via <Teleport to="body"> - several call sites live inside an
* ancestor that creates its own CSS stacking context (.app-sidebar has
* position:sticky; .txn-col has container-type:inline-size, which
* implies layout containment - both always create one, with or without
* an explicit z-index). A modal nested inside either gets its own
* z-index trapped within that ancestor's local stacking order, no
* matter how high the value - it can be painted UNDER later, unrelated
* page content regardless (confirmed for real: the sidebar's own delete
* confirm rendered behind the main content, unclickable). Teleporting
* to <body> renders it outside any ancestor's stacking context entirely,
* the standard fix for this class of bug - not a z-index increase, which
* cannot fix a trapped stacking context no matter the number chosen.
*/ */
import { toRef } from 'vue' import { toRef } from 'vue'
import { useModalFocus } from '../composables/useModalFocus' import { useModalFocus } from '../composables/useModalFocus'
@ -28,24 +42,26 @@ const { overlayRef } = useModalFocus(toRef(props, 'visible'))
</script> </script>
<template> <template>
<div <Teleport to="body">
v-if="visible" <div
ref="overlayRef" v-if="visible"
class="modal-overlay" ref="overlayRef"
tabindex="-1" class="modal-overlay"
@click.self="!busy && emit('cancel')" tabindex="-1"
@keydown.esc="!busy && emit('cancel')" @click.self="!busy && emit('cancel')"
> @keydown.esc="!busy && emit('cancel')"
<div class="modal-card card" role="dialog" aria-modal="true" :aria-label="title"> >
<h2><i class="fa-solid" :class="titleIcon"></i>{{ title }}</h2> <div class="modal-card card" role="dialog" aria-modal="true" :aria-label="title">
<p class="modal-message">{{ message }}</p> <h2><i class="fa-solid" :class="titleIcon"></i>{{ title }}</h2>
<div class="modal-actions"> <p class="modal-message">{{ message }}</p>
<button type="button" class="btn btn-ghost" :disabled="busy" @click="emit('cancel')">{{ cancelLabel }}</button> <div class="modal-actions">
<button type="button" class="btn" :class="danger ? 'btn-danger' : 'btn-primary'" :disabled="busy" @click="emit('confirm')"> <button type="button" class="btn btn-ghost" :disabled="busy" @click="emit('cancel')">{{ cancelLabel }}</button>
<i class="fa-solid" :class="busy ? 'fa-spinner fa-spin' : confirmIcon"></i> <button type="button" class="btn" :class="danger ? 'btn-danger' : 'btn-primary'" :disabled="busy" @click="emit('confirm')">
{{ confirmLabel }} <i class="fa-solid" :class="busy ? 'fa-spinner fa-spin' : confirmIcon"></i>
</button> {{ confirmLabel }}
</button>
</div>
</div> </div>
</div> </div>
</div> </Teleport>
</template> </template>

View File

@ -7,6 +7,12 @@
* ConfirmModal for the actual delete (DocumentNavBar owns that step - * ConfirmModal for the actual delete (DocumentNavBar owns that step -
* same two-modal "pick an action, then confirm the destructive one" * same two-modal "pick an action, then confirm the destructive one"
* pattern already established by "Move to project"). * pattern already established by "Move to project").
*
* Rendered via <Teleport to="body"> - its own call site lives inside
* .txn-col, which creates its own CSS stacking context
* (container-type:inline-size implies layout containment) - see
* ConfirmModal.vue's own comment for the full reasoning and the real
* bug this fixes.
*/ */
import { ref, toRef, watch } from 'vue' import { ref, toRef, watch } from 'vue'
import { useModalFocus } from '../composables/useModalFocus' import { useModalFocus } from '../composables/useModalFocus'
@ -32,41 +38,43 @@ function handleRename() {
</script> </script>
<template> <template>
<div <Teleport to="body">
v-if="visible" <div
ref="overlayRef" v-if="visible"
class="modal-overlay" ref="overlayRef"
tabindex="-1" class="modal-overlay"
@click.self="!renaming && emit('cancel')" tabindex="-1"
@keydown.esc="!renaming && emit('cancel')" @click.self="!renaming && emit('cancel')"
> @keydown.esc="!renaming && emit('cancel')"
<div class="modal-card card" role="dialog" aria-modal="true" aria-label="Document options"> >
<h2><i class="fa-solid fa-file-lines"></i>Document options</h2> <div class="modal-card card" role="dialog" aria-modal="true" aria-label="Document options">
<h2><i class="fa-solid fa-file-lines"></i>Document options</h2>
<div class="modal-field"> <div class="modal-field">
<label>File name</label> <label>File name</label>
<div class="modal-field-row"> <div class="modal-field-row">
<input v-model="draft" type="text" class="modal-input" :disabled="renaming" @keyup.enter="handleRename"> <input v-model="draft" type="text" class="modal-input" :disabled="renaming" @keyup.enter="handleRename">
<button <button
type="button" type="button"
class="btn-toggle" class="btn-toggle"
:disabled="renaming || !trimmedDraft() || trimmedDraft() === fileName" :disabled="renaming || !trimmedDraft() || trimmedDraft() === fileName"
@click="handleRename" @click="handleRename"
> >
<i class="fa-solid" :class="renaming ? 'fa-spinner fa-spin' : 'fa-check'"></i> <i class="fa-solid" :class="renaming ? 'fa-spinner fa-spin' : 'fa-check'"></i>
Save Save
</button> </button>
</div>
</div>
<button type="button" class="modal-danger-btn" :disabled="renaming" @click="emit('delete')">
<i class="fa-solid fa-trash"></i>
Delete this document
</button>
<div class="modal-actions">
<button type="button" class="btn btn-ghost" :disabled="renaming" @click="emit('cancel')">Close</button>
</div> </div>
</div> </div>
<button type="button" class="modal-danger-btn" :disabled="renaming" @click="emit('delete')">
<i class="fa-solid fa-trash"></i>
Delete this document
</button>
<div class="modal-actions">
<button type="button" class="btn btn-ghost" :disabled="renaming" @click="emit('cancel')">Close</button>
</div>
</div> </div>
</div> </Teleport>
</template> </template>

View File

@ -6,6 +6,12 @@
* more than one document is loaded - replaces the old separate "Download * more than one document is loaded - replaces the old separate "Download
* All" button with one Download button that asks which, rather than * All" button with one Download button that asks which, rather than
* needing a second button in the UI for the "all" case. * needing a second button in the UI for the "all" case.
*
* Rendered via <Teleport to="body"> - its own call site lives inside
* .txn-col, which creates its own CSS stacking context
* (container-type:inline-size implies layout containment) - see
* ConfirmModal.vue's own comment for the full reasoning and the real
* bug this fixes.
*/ */
import { toRef } from 'vue' import { toRef } from 'vue'
import { useModalFocus } from '../composables/useModalFocus' import { useModalFocus } from '../composables/useModalFocus'
@ -20,30 +26,32 @@ const { overlayRef } = useModalFocus(toRef(props, 'visible'))
</script> </script>
<template> <template>
<div <Teleport to="body">
v-if="visible" <div
ref="overlayRef" v-if="visible"
class="modal-overlay" ref="overlayRef"
tabindex="-1" class="modal-overlay"
@click.self="emit('cancel')" tabindex="-1"
@keydown.esc="emit('cancel')" @click.self="emit('cancel')"
> @keydown.esc="emit('cancel')"
<div class="modal-card card" role="dialog" aria-modal="true" aria-label="Download"> >
<h2><i class="fa-solid fa-download"></i>Download</h2> <div class="modal-card card" role="dialog" aria-modal="true" aria-label="Download">
<p class="modal-message">{{ count }} documents are loaded. Which would you like to download?</p> <h2><i class="fa-solid fa-download"></i>Download</h2>
<div class="modal-actions modal-actions-stack"> <p class="modal-message">{{ count }} documents are loaded. Which would you like to download?</p>
<button type="button" class="btn btn-ghost" @click="emit('current')"> <div class="modal-actions modal-actions-stack">
<i class="fa-solid fa-file-excel"></i> <button type="button" class="btn btn-ghost" @click="emit('current')">
Current document only <i class="fa-solid fa-file-excel"></i>
</button> Current document only
<button type="button" class="btn btn-primary" @click="emit('all')"> </button>
<i class="fa-solid fa-download"></i> <button type="button" class="btn btn-primary" @click="emit('all')">
All {{ count }} documents <i class="fa-solid fa-download"></i>
</button> All {{ count }} documents
</div> </button>
<div class="modal-actions"> </div>
<button type="button" class="btn btn-ghost" @click="emit('cancel')">Cancel</button> <div class="modal-actions">
<button type="button" class="btn btn-ghost" @click="emit('cancel')">Cancel</button>
</div>
</div> </div>
</div> </div>
</div> </Teleport>
</template> </template>