diff --git a/web/src/lib/actions/click-outside.ts b/web/src/lib/actions/click-outside.ts index af4ec8695..292e28e71 100644 --- a/web/src/lib/actions/click-outside.ts +++ b/web/src/lib/actions/click-outside.ts @@ -12,10 +12,9 @@ interface Options { * @param options Object containing onOutclick and onEscape functions * @returns */ -export function clickOutside(node: HTMLElement, options: Options = {}): ActionReturn { - const { onOutclick, onEscape } = options; - +export function clickOutside(node: HTMLElement, options: Options = {}): ActionReturn { const handleClick = (event: MouseEvent) => { + const { onOutclick } = options; const targetNode = event.target as Node | null; if (node.contains(targetNode)) { return; @@ -25,6 +24,7 @@ export function clickOutside(node: HTMLElement, options: Options = {}): ActionRe }; const handleKey = (event: KeyboardEvent) => { + const { onEscape } = options; if (!matchesShortcut(event, { key: 'Escape' })) { return; } @@ -39,6 +39,9 @@ export function clickOutside(node: HTMLElement, options: Options = {}): ActionRe node.addEventListener('keydown', handleKey, { capture: false }); return { + update(newOptions: Options) { + options = newOptions; + }, destroy() { document.removeEventListener('mousedown', handleClick, false); node.removeEventListener('keydown', handleKey, false); diff --git a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte index 347f4be04..ab749a45a 100644 --- a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte +++ b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte @@ -362,7 +362,7 @@ class="relative w-fit p-4 pt-12 sm:px-6" use:clickOutside={{ onOutclick: handleCancelEditName, - onEscape: handleCancelEditName, + onEscape: isEditingName ? handleCancelEditName : undefined, }} use:listNavigation={suggestionContainer} >