refactor(ui): update BasePane to use clickOutside action
Replace manual click event listener with clickOutside action for the pane backdrop click handling. This simplifies the code and ensures consistent click-outside behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7300bd672b
commit
dcca9eb6e5
1 changed files with 3 additions and 18 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fade } from 'svelte/transition'
|
import { fade } from 'svelte/transition'
|
||||||
|
import { clickOutside } from '$lib/actions/clickOutside'
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
|
|
||||||
interface BasePaneProps {
|
interface BasePaneProps {
|
||||||
|
|
@ -40,24 +41,6 @@
|
||||||
return () => window.removeEventListener('keydown', handleKeydown)
|
return () => window.removeEventListener('keydown', handleKeydown)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle click outside
|
|
||||||
$effect(() => {
|
|
||||||
if (!isOpen || !closeOnBackdrop) return
|
|
||||||
|
|
||||||
function handleClickOutside(e: MouseEvent) {
|
|
||||||
if (paneElement && !paneElement.contains(e.target as Node)) {
|
|
||||||
handleClose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use capture phase to ensure we catch the click before other handlers
|
|
||||||
setTimeout(() => {
|
|
||||||
document.addEventListener('click', handleClickOutside, true)
|
|
||||||
}, 0)
|
|
||||||
|
|
||||||
return () => document.removeEventListener('click', handleClickOutside, true)
|
|
||||||
})
|
|
||||||
|
|
||||||
function handleClose() {
|
function handleClose() {
|
||||||
isOpen = false
|
isOpen = false
|
||||||
onClose?.()
|
onClose?.()
|
||||||
|
|
@ -133,6 +116,8 @@
|
||||||
transition:fade={{ duration: 150 }}
|
transition:fade={{ duration: 150 }}
|
||||||
role="dialog"
|
role="dialog"
|
||||||
aria-modal="false"
|
aria-modal="false"
|
||||||
|
use:clickOutside={{ enabled: closeOnBackdrop }}
|
||||||
|
on:clickoutside={handleClose}
|
||||||
>
|
>
|
||||||
{#if children}
|
{#if children}
|
||||||
{@render children()}
|
{@render children()}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue