Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 28x 28x 28x 28x 1x 5x 5x 5x 5x 1x 28x 28x 28x 28x 28x 28x 1x 1x 5x 5x 5x 5x 5x 5x 1x 1x | <template>
<!-- Teleported to <body> so no ancestor can ever turn this into a clipped,
non-fixed box. A `transform`, `filter` or `contain` anywhere up the tree
would otherwise make `position: fixed` resolve against that ancestor
instead of the viewport. -->
<Teleport to="body">
<div
ref="overlay"
:class="[
'fixed inset-0 bg-black/60 overflow-y-auto overscroll-contain',
Z_INDEX_CLASS,
]"
role="dialog"
aria-modal="true"
:aria-label="label"
data-testid="modal-overlay"
@click.self="close"
@keydown.esc.stop.prevent="close"
@keydown.tab="trapFocus"
>
<!-- Pinned to the OVERLAY, not the card, so it stays reachable at any
scroll position. The old button was absolute on the card and left
the viewport as soon as the user scrolled to read the content
(SB-890). -->
<button
ref="closeButton"
type="button"
:aria-label="closeLabel"
class="fixed top-3 right-3 sm:top-4 sm:right-4 z-10 inline-flex items-center justify-center w-9 h-9 rounded-full bg-card/90 backdrop-blur border border-line text-fg-muted shadow-lg hover:text-fg hover:bg-surface-alt transition-colors"
data-testid="modal-close"
@click="close"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-5 h-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
<div
:class="[
'min-h-full flex justify-center p-3 sm:p-6',
align === 'end' ? 'items-end sm:items-center' : 'items-start',
]"
>
<div
:class="['relative w-full bg-card rounded-lg shadow-2xl', maxWidth]"
@click.stop
>
<slot />
</div>
</div>
</div>
</Teleport>
</template>
<script setup>
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
/**
* A modal that can always be closed (SB-890).
*
* The previous inline overlay put its close button `absolute` on the card, had
* no Escape handler, and left the page scrolling behind it. On a short window
* the card outgrew the viewport, and scrolling to read it carried the only
* visible exit off-screen — every escape route blocked at once.
*
* Three independent ways out, so no single failure traps anyone: the pinned
* button, Escape, and a backdrop click.
*/
/**
* Above the nav (SB-896).
*
* `nav.auth-nav` is `position: relative; z-index: 1000` — page chrome sitting
* in the same band the app uses for modals (App.vue, ConfirmModal, every admin
* modal are all 1000, and only win by appearing later in the DOM). At z-50
* this overlay lost outright: the nav painted over the top strip of the
* viewport and swallowed clicks on the close button, so a user at the top of
* the page could not shut the modal at all.
*
* 1200 clears both the nav and the "above a modal" layer already in use
* (RosterManager 1100). The real fix is to take the nav out of the modal band
* entirely, which is riskier and tracked separately.
*/
const Z_INDEX_CLASS = 'z-[1200]';
const props = defineProps({
// Accessible name for the dialog.
label: { type: String, default: 'Dialog' },
closeLabel: { type: String, default: 'Close' },
maxWidth: { type: String, default: 'max-w-4xl' },
/**
* Where the panel sits in the viewport. 'start' is the usual dialog, pinned
* near the top. 'end' is a phone action sheet: the panel rises from the
* bottom edge, within a thumb's reach of the row that opened it, and
* re-centres on a wide screen where a bottom sheet would look stranded.
*/
align: {
type: String,
default: 'start',
validator: value => ['start', 'end'].includes(value),
},
});
const emit = defineEmits(['close']);
const overlay = ref(null);
const closeButton = ref(null);
let previouslyFocused = null;
const close = () => emit('close');
const FOCUSABLE =
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
const focusable = () =>
overlay.value
? [...overlay.value.querySelectorAll(FOCUSABLE)].filter(
el => el.offsetParent !== null || el === closeButton.value
)
: [];
/**
* Keep Tab inside the dialog. Without this, tabbing walks out into the page
* behind — which is still there, just visually covered.
*/
const trapFocus = event => {
const items = focusable();
if (items.length === 0) return;
const first = items[0];
const last = items[items.length - 1];
const active = document.activeElement;
if (event.shiftKey && (active === first || !overlay.value.contains(active))) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && active === last) {
event.preventDefault();
first.focus();
}
};
/**
* Lock the page behind the modal.
*
* `overflow: hidden` on body preserves the scroll position, so closing does not
* jump the reader back to the top. The padding compensates for the scrollbar
* that disappears with it, which would otherwise shift the whole layout
* sideways as the modal opens.
*/
let previousOverflow = '';
let previousPaddingRight = '';
const lockScroll = () => {
const { body } = document;
const scrollbar = window.innerWidth - document.documentElement.clientWidth;
previousOverflow = body.style.overflow;
previousPaddingRight = body.style.paddingRight;
body.style.overflow = 'hidden';
if (scrollbar > 0) body.style.paddingRight = `${scrollbar}px`;
};
const unlockScroll = () => {
const { body } = document;
body.style.overflow = previousOverflow;
body.style.paddingRight = previousPaddingRight;
};
onMounted(async () => {
previouslyFocused = document.activeElement;
lockScroll();
await nextTick();
// Focus the dialog itself rather than the first control, so a screen reader
// announces the dialog before its contents, and Escape works immediately.
closeButton.value?.focus();
});
onBeforeUnmount(() => {
unlockScroll();
// Return focus to whatever opened the modal — usually the match row — so the
// reader does not land back at the top of the document.
if (previouslyFocused instanceof HTMLElement) {
previouslyFocused.focus();
}
});
defineExpose({ close, label: props.label });
</script>
|