fix: close modal shortcut closes only the top modal (#29830)

This commit is contained in:
G30 2026-09-09 12:11:38 -04:00 committed by GitHub
parent 12b14124b9
commit e4d65d0351
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 9 deletions

View file

@ -3,6 +3,8 @@
import { onMount, getContext, createEventDispatcher, onDestroy, tick } from 'svelte';
import * as FocusTrap from 'focus-trap';
import { settings } from '$lib/stores';
import { matchKeybinding, Shortcut } from '$lib/shortcuts';
const i18n = getContext('i18n');
const dispatch = createEventDispatcher();
@ -45,7 +47,10 @@
};
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
if (
event.key === 'Escape' ||
($settings?.keyboardShortcuts !== false && matchKeybinding(event) === Shortcut.CLOSE_MODAL)
) {
cancelHandler();
}
@ -113,7 +118,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
bind:this={modalElement}
class=" fixed top-0 right-0 left-0 bottom-0 bg-black/60 w-full h-screen max-h-[100dvh] flex justify-center z-99999999 overflow-hidden overscroll-contain"
class="modal fixed top-0 right-0 left-0 bottom-0 bg-black/60 w-full h-screen max-h-[100dvh] flex justify-center z-99999999 overflow-hidden overscroll-contain"
in:fade={{ duration: 10 }}
on:mousedown={() => {
cancelHandler();

View file

@ -2,6 +2,8 @@
import { onDestroy, onMount } from 'svelte';
import { flyAndScale } from '$lib/utils/transitions';
import { fade, fly, slide } from 'svelte/transition';
import { settings } from '$lib/stores';
import { matchKeybinding, Shortcut } from '$lib/shortcuts';
export let show = false;
export let className = '';
@ -12,7 +14,12 @@
let mounted = false;
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && isTopModal()) {
if (
(event.key === 'Escape' ||
($settings?.keyboardShortcuts !== false &&
matchKeybinding(event) === Shortcut.CLOSE_MODAL)) &&
isTopModal()
) {
console.log('Escape');
show = false;
}

View file

@ -6,6 +6,8 @@
const { saveAs } = fileSaver;
import { WEBUI_BASE_URL } from '$lib/constants';
import { settings } from '$lib/stores';
import { matchKeybinding, Shortcut } from '$lib/shortcuts';
import PanzoomContainer from '$lib/components/common/PanzoomContainer.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
@ -18,7 +20,10 @@
let previewElement = null;
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
if (
event.key === 'Escape' ||
($settings?.keyboardShortcuts !== false && matchKeybinding(event) === Shortcut.CLOSE_MODAL)
) {
console.log('Escape');
show = false;
}

View file

@ -4,6 +4,8 @@
import { flyAndScale } from '$lib/utils/transitions';
import * as FocusTrap from 'focus-trap';
import { settings } from '$lib/stores';
import { matchKeybinding, Shortcut } from '$lib/shortcuts';
export let show = true;
export let size = 'md';
export let containerClassName = 'p-3';
@ -40,7 +42,12 @@
};
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && isTopModal()) {
if (
(event.key === 'Escape' ||
($settings?.keyboardShortcuts !== false &&
matchKeybinding(event) === Shortcut.CLOSE_MODAL)) &&
isTopModal()
) {
console.log('Escape');
show = false;
}

View file

@ -328,10 +328,6 @@
console.log('Shortcut triggered: SHOW_SHORTCUTS');
event.preventDefault();
showSettings.set('shortcuts');
} else if (shortcut === Shortcut.CLOSE_MODAL) {
console.log('Shortcut triggered: CLOSE_MODAL');
event.preventDefault();
showSettings.set(false);
} else if (shortcut === Shortcut.OPEN_MODEL_SELECTOR) {
console.log('Shortcut triggered: OPEN_MODEL_SELECTOR');
event.preventDefault();