Skip to content

Commit bf93e11

Browse files
committed
Fixed modal closing with esc key not working
1 parent aee5ccd commit bf93e11

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/lib/components/common/ExpandableLog.svelte

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
import { onDestroy, onMount } from 'svelte';
3+
24
/** @type {Array<{text: string, highlight: boolean}>} */
35
export let logParts = [];
46
export let highlight = false;
@@ -8,12 +10,26 @@
810
911
function expandDetails() {
1012
showDetails = true;
11-
// Restore focus on modal, otherwise it will not be possible to close it using the esc key
13+
restoreModalFocus();
14+
}
15+
16+
/**
17+
* Restore focus on modal, otherwise it will not be possible to close it using the esc key
18+
*/
19+
function restoreModalFocus() {
1220
const modal = document.querySelector('.modal.show');
1321
if (modal instanceof HTMLElement) {
1422
modal.focus();
1523
}
1624
}
25+
26+
onMount(() => {
27+
restoreModalFocus();
28+
});
29+
30+
onDestroy(() => {
31+
restoreModalFocus();
32+
});
1733
</script>
1834

1935
<div class="expandable-log">

0 commit comments

Comments
 (0)