Restore previous focus when modal dialogs close.

This commit is contained in:
Leo Vasanko
2025-12-10 15:40:05 +00:00
parent ce783cbf57
commit 4208f78f4f
4 changed files with 174 additions and 6 deletions
@@ -49,6 +49,8 @@ const emit = defineEmits(['close', 'copied'])
const linkUrl = ref(null)
const expiresAt = ref(null)
const actionsRow = ref(null)
// Store the element that had focus before modal opened
const previouslyFocusedElement = ref(null)
async function generateLink() {
try {
@@ -102,6 +104,8 @@ const handleActionsKeydown = (event) => {
}
onMounted(() => {
// Save currently focused element before modal takes focus
previouslyFocusedElement.value = document.activeElement
// Hold backdrop before fetch to avoid gap if auth iframe shows
holdGlobalBackdrop()
generateLink()
@@ -110,6 +114,11 @@ onMounted(() => {
onUnmounted(() => {
// Release backdrop when modal closes
releaseGlobalBackdrop()
// Restore focus when modal closes
const prev = previouslyFocusedElement.value
if (prev && document.body.contains(prev) && !prev.disabled) {
prev.focus()
}
})
</script>